From 5c32704e57d8a7774b39650fc04fac86e76ca5b1 Mon Sep 17 00:00:00 2001 From: hackbard Date: Sun, 15 May 2016 12:28:59 +0200 Subject: [PATCH 1/1] initial checkin of modular app --- app/config.xml | 26 ++++++ app/www/css/index.css | 97 ++++++++++++++++++++ app/www/index.html | 99 ++++++++++++++++++++ app/www/js/config.js | 53 +++++++++++ app/www/js/index.js | 204 ++++++++++++++++++++++++++++++++++++++++++ app/www/js/jquery.js | 1 + 6 files changed, 480 insertions(+) create mode 100644 app/config.xml create mode 100644 app/www/css/index.css create mode 100644 app/www/index.html create mode 100644 app/www/js/config.js create mode 100644 app/www/js/index.js create mode 120000 app/www/js/jquery.js diff --git a/app/config.xml b/app/config.xml new file mode 100644 index 0000000..f781c08 --- /dev/null +++ b/app/config.xml @@ -0,0 +1,26 @@ + + + Modular + + A simple app to count whatever you like. + + + hackbard@hackdaworld.org + + + + + + + + + + + + + + + + + + diff --git a/app/www/css/index.css b/app/www/css/index.css new file mode 100644 index 0000000..7714f9d --- /dev/null +++ b/app/www/css/index.css @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +html { + height: 100%; +} + +body { + height: 100%; + margin: 0; + background-color: black; +} + +#main { + width: 100%; + height: 100%; + display: none; +} + +#moddiag { + width: 100%; + height: 100%; +} + +.mod { + width: 42.5%; + height: 80%; + margin-top: 5%; + margin-left: 5%; + background-color: white; + float: left; +} + +.mdhead { + width: 100%; + height: 10%; + text-align: center; +} + +.mdmain { + width: 97%; + height: 90%; + margin-left: 3%; + overflow: auto; +} + +.mdcbtn { + width: 90%; + height: 10%; + margin: 3%; + text-align: center; + background-color: #ddd; +} + +.mdcline { + width: 30%; + float: left; +} + +.mdcinput { + width: 70%; + float: left; +} + +#mdnc { + width: 100%; + margin-top: 3%; + clear: left; +} + +.item { + float: left; + text-align: center; +} + +#mdcont { +} + +#mdnew { +} + diff --git a/app/www/index.html b/app/www/index.html new file mode 100644 index 0000000..8d44014 --- /dev/null +++ b/app/www/index.html @@ -0,0 +1,99 @@ + + + + + + + + + Modular + + + + + + + + + + + + + + + + + +
+
+
+
+
+ Continue counting ... +
+
+
+
+
+
+ New setup! +
+
+
Name
+
+ +
+
Total
+
+ +
+
Rows
+
+ +
+
Columns
+
+ +
+
+
+
+
+
+ + + diff --git a/app/www/js/config.js b/app/www/js/config.js new file mode 100644 index 0000000..19b0480 --- /dev/null +++ b/app/www/js/config.js @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* db */ + +var db_conf_store = { + keyname: true, + keytype: 'autoIncrement', + content: { + 1: [ + { + 'name': 'FooBar', + 'items': 2, + 'rows': 1, + 'cols': 2, + 'itemname': ['Foo','Bar'], + 'cnt': [0,0], + 'colors': ['red','blue'] + }, + { + 'name': 'Alice, Bob, Dan and Eve', + 'items': 4, + 'rows': 2, + 'cols': 2, + 'itemname': ['Alice','Bob','Dan','Eve'], + 'cnt': [0,0,0,0], + 'colors': ['red','green','blue','yellow'] + } + ] + } +} + +var db_count_store = { + keyname: true, + keytype: 'autoIncrement' +} + diff --git a/app/www/js/index.js b/app/www/js/index.js new file mode 100644 index 0000000..04067dc --- /dev/null +++ b/app/www/js/index.js @@ -0,0 +1,204 @@ +/* + * + * modular: simple app to count whatever you like + * author: hackbrd@hackdaworld.org + * + */ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var modular = { + init: function() { + document.addEventListener('deviceready',this.startup,false); + }, + startup: function() { + // indexed db + //idb.name='modular'; + //idb.del(); + var stores={ + 'conf': db_conf_store, + 'count': db_count_store + }; + idb.init('modular',modular.dbcallback,1,stores); + }, + dbcallback: function() { + idb.get_store_items('conf',function(item) { + var html=""; + for(var i in item) { + cl("item "+i); + objdbg(item[i]); + html+="
"+ + item[i].name+"
"; + } + $('#mdcont').html(html); + vert_align_text('.mdhead'); + vert_align_text('.mdcbtn'); + $('.mdcbtn').click(function(event) { + var conf=$(this).attr('data-id'); + modular.init_config(conf); + }); + }); + $('.mdni').change(function(event) { + modular.md_input_event(event.target.id); + }); + }, + md_input_event: function(id) { + var html=""; + var valid=true; + switch(id) { + case 'mditot': + case 'mdirows': + case 'mdicols': + var rows=$('#mdirows').val(); + var cols=$('#mdicols').val(); + var tot=$('#mditot').val(); + if(tot>rows*cols) { + html="
Pleas increas rows "+ + "and/or columns ..."; + valid=false; + } + if((rows>0)&&(cols>0)) + html+="
Row-Column: Name Color"; + else + valid=false; + var t=0; + var s="
"; + for(var r=1;r<=rows;r++) { + for(var c=1;c<=cols;c++) { + t+=1; + if(tot"+ + "
"; + } + } + var go=""; + if(valid) + go="
"; + $('#mdnc').html(html+s+go); + if(valid) + $('#mdngo').click(function() { + var na=[]; + var ca=[]; + var cnta=[]; + $('.mdiin').each(function() { + na.push($(this).val()); + cnta.push(0); + }); + $('.mdiic').each(function() { + ca.push($(this).val()); + }); + var item={ + name: $('#mdiname').val(), + items: tot, + rows: rows, + cols: cols, + itemname: na, + cnt: cnta, + colors: ca + }; + idb.add_store_item('conf',item, + function() { + modular.init_config('last'); + }); + }); + break; + default: + break; + } + }, + confignum: 0, + config: {}, + init_config: function(conf) { + if(conf=='last') { + cl("starting up last configuration!"); + idb.get_store_items('conf',function(item) { + for(var i in item); + modular.start_counter(item[i]); + modular.confignum=Number(i); + modular.config=item[i]; + },0,-1); + } + else { + cl("starting configuration "+conf); + idb.get_item_by_key('conf',Number(conf),function(item) { + modular.start_counter(item); + modular.confignum=Number(conf); + modular.config=item; + }); + } + }, + start_counter: function(conf) { + $('#moddiag').css('display','none'); + $('#main').css('display','block'); + var ww=100/conf.cols; + var wh=100/conf.rows; + var html=""; + for(var i=1;i<=conf.items;i++) { + html+="
"; + } + $('#main').html(html); + for(var i=1;i<=conf.items;i++) { + var id="#item"+i; + $(id).css('width',ww+'%'); + $(id).css('height',wh+'%'); + $(id).css('background-color',conf.colors[i-1]); + $(id).html(conf.itemname[i-1]+": "+conf.cnt[i-1]); + vert_align_text(id); + } + $('.item').click(function(event) { + var id='#'+event.target.id; + var istr=event.target.id.replace("item",""); + var i=Number(istr); + modular.inc_counter(id,i) + }); + }, + inc_counter: function(id,i) { + var conf=modular.config; + var cn=modular.confignum; + conf.cnt[i-1]+=1; + var html=conf.itemname[i-1]+": "+conf.cnt[i-1]; + cntitem={ + date: (new Date()).toString(), + confignum: cn, + itemnum: i-1, + counter: conf.cnt[i-1] + }; + idb.add_store_item('count',cntitem,function() { + cl("increased counter for item "+i-1+ + " to "+conf.cnt[i-1]); + idb.update_store_item('conf',cn,conf,function() { + $(id).html(html); + }); + }); + } +}; + +$(document).ready(function() { + if('cordova' in window) { + modular.init(); + } + else { + modular.startup(); + } +}); + diff --git a/app/www/js/jquery.js b/app/www/js/jquery.js new file mode 120000 index 0000000..195a6cd --- /dev/null +++ b/app/www/js/jquery.js @@ -0,0 +1 @@ +jquery-2.2.3.min.js \ No newline at end of file -- 2.39.2