Skip to content
Browse files

First commit

  • Loading branch information...
1 parent b06d3af commit 75236b3e5c5d6280b710a49cd55a62ca30a1197a @mlmiller committed
View
7 apps/inventory/.couchappignore
@@ -0,0 +1,7 @@
+[
+ // filenames matching these regexps will not be pushed to the database
+ // uncomment to activate; separate entries with ","
+ // ".*~$"
+ // ".*\\.swp$"
+ // ".*\\.bak$"
+]
View
1 apps/inventory/.couchapprc
@@ -0,0 +1 @@
+{}
View
21 apps/inventory/README.md
@@ -0,0 +1,21 @@
+# inventory
+
+inventory is a CouchDB application that was created from the content from https://www.ibm.com/developerworks/web/library/wa-couchdb/. Here we have simply bundled this for distribution via the couchapp framework for simple installation. This is a simple example of an application to create and track inventory.
+
+## Requirements
+
+cloudant hosted account (sign up at <https://cloudant.com/#!/solutions/cloud>) or stock CouchDB, couchapp
+
+## Install
+
+<pre><code>
+cd inventory
+couchapp push 'http://<user>:<pwd>@<user>.cloudant.com:5984/<db>'
+
+To configure the application display, modify the file:
+
+ _attachments/index.html
+
+Now view your app at
+ http://&lt;user&gt;.cloudant.com:5984/&lt;db&gt;/_design/myDesign/index.html
+
View
39 apps/inventory/_attachments/index.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>MyHomeStuff2</title>
+ <script src="/_utils/script/jquery.js"></script>
+ <script src="/_utils/script/jquery.couch.js"></script>
+ <script src="script.js"></script>
+ </head>
+ <body>
+ <h3>Overview</h3>
+ <ul id="itemData" ></ul>
+
+ <h3>Details</h3>
+ <form name="itemForm">
+ <input type="hidden" name="id" id="idId" />
+ <input type="hidden" name="rev" id="revId"/>
+ <label for="amount">Qty: </label>
+ <input type="text" name="amount" id="amountId" size = 3/>
+ <label for="name">Name: </label>
+ <input type="text" name="name" id="nameId" size=12 />
+ <br><br>
+ <input type="button" id="createId" value="create" />
+ <input type="button" id="updateId" value="update" />
+ <input type="button" id="deleteId" value="delete" />
+ </form>
+
+ <h3>Replicate</h3>
+ <form>
+ <label for="sourceDBId">Source: </label>
+ <input id="sourceDBId" type="text"></input>
+ <br><br>
+ <label for="targetDBId">Target: </label>
+ <input id="targetDBId" type="text"></input>
+ <br><br>
+ <input id="replicateId" type="button" value="replicate"></input>
+ </form>
+
+ </body>
+</html>
View
107 apps/inventory/_attachments/script.js
@@ -0,0 +1,107 @@
+var db = $.couch.db(getCurrentDBName());
+
+function getCurrentDBName() {
+ return window.location.pathname.split("/")[1];
+}
+
+$(document).ready(function() {
+
+ //init stuff
+ refreshItems();
+ $('#sourceDBId').val(db.name);
+ $('#targetDBId').val(db.name + "-copy");
+
+ //event handler crud stuff
+ $('input#createId').click(function(e) {
+
+ if ($('#nameId').val().length == 0) {
+ return;
+ }
+
+ var aTask = { amount: $('#amountId').val(), name: $('#nameId').val() }
+
+ db.saveDoc(aTask, { success: function(resp) {
+ refreshItems();
+ }});
+
+ clearForm();
+ });
+
+ $('input#deleteId').click(function(e) {
+
+ if ($('#idId').val().length == 0) {
+ return;
+ }
+
+ var aTask = {
+ _id: $('#idId').val(),
+ _rev: $('#revId').val()
+ }
+ db.removeDoc(aTask, { success: function(resp) {
+ refreshItems();
+ }});
+
+ clearForm();
+ });
+
+ $('input#updateId').click(function(e) {
+
+ if ($('#idId').val().length == 0) {
+ return;
+ }
+
+ var aTask = {
+ _id: $('#idId').val(),
+ _rev: $('#revId').val(),
+ amount: $('#amountId').val(),
+ name:$('#nameId').val()
+ }
+ db.saveDoc(aTask, { success: function(resp) {
+ refreshItems();
+ }});
+ });
+
+
+
+
+$('#replicateId').click(function() {
+ var sourceDB = $('#sourceDBId').val();
+ var targetDB = $('#targetDBId').val();
+ $.couch.replicate(sourceDB, targetDB, {
+ success: function(data){alert('Replication was performed');},
+ error: function(req, textStatus, errorThrown){alert('Error '+ textStatus);}
+ });
+});
+});
+
+function refreshItems() {
+ $("ul#itemData").empty();
+
+ db.view("myDesign/myView", {
+ success: function(data){
+ data.rows.map(function(row) {
+ $('ul#itemData').append('<li id="'+row.value._id+'">'
+ +row.value.amount
+ +" x "
+ +row.value.name
+ +'</li>');
+
+ $('#'+row.value._id).click(function() {
+ $('#idId').val(row.value._id);
+ $('#revId').val(row.value._rev);
+ $('#amountId').val(row.value.amount);
+ $('#nameId').val(row.value.name);
+ return false;
+ });
+ });
+ },
+ error: function(req, textStatus, errorThrown){alert('Error '+ textStatus);}
+ });
+}
+
+function clearForm() {
+ $('#idId').val('');
+ $('#revId').val('');
+ $('#amountId').val('');
+ $('#nameId').val('');
+};
View
4 apps/inventory/_docs/doc1.json
@@ -0,0 +1,4 @@
+{
+ "name":"table",
+ "amount":3
+}
View
1 apps/inventory/_id
@@ -0,0 +1 @@
+_design/myDesign
View
4 apps/inventory/couchapp.json
@@ -0,0 +1,4 @@
+{
+ "name": "inventory",
+ "description": "inventory is a CouchDB application that was created from the content from https://www.ibm.com/developerworks/web/library/wa-couchdb/. Here we have simply bundled this for distribution via the couchapp framework for simple installation. This is a simple example of an application to create and track inventory."
+}
View
5 apps/inventory/views/myView/map.js
@@ -0,0 +1,5 @@
+function(doc) {
+ if (doc.name && doc.amount) {
+ emit(doc._id, doc);
+ }
+}

0 comments on commit 75236b3

Please sign in to comment.
Something went wrong with that request. Please try again.