Skip to content

Commit

Permalink
Finish #22
Browse files Browse the repository at this point in the history
Conflicts:
	www/js/pockets.bundle.js
	www/js/pockets.bundle.js.map
  • Loading branch information
orweinberger committed Mar 13, 2015
2 parents 5d2f7c2 + bfe87fb commit 0239293
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 75 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"watchify": "^2.4.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}
}
},
"cordovaPlugins": []
}
9 changes: 9 additions & 0 deletions www/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
.btn-addpocket {
background-color: #dd4b39;
border-color: #d43f3a;
}

.btn-rootinfo {
background-color:#ecf0f1;
border-color:#f2f2f2;
color:#222;
}

.btn-addpocket:hover, .btn-addpocket:focus, .btn-addpocket:active {
Expand All @@ -69,4 +74,8 @@

.children {
display: inline-block;
}

#qrcode img {
margin:0 auto;
}
3 changes: 3 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
<script src="js/pockets.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/qrcode.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/directives.js"></script>
</head>
<body ng-app="starter">
<!--
Expand Down
2 changes: 1 addition & 1 deletion www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'starter.directives', 'ngCordova'])

.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
Expand Down
177 changes: 111 additions & 66 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
angular.module('starter.controllers', [])
function shadeBlend(p, c0, c1) {
var n = p < 0 ? p * -1 : p, u = Math.round, w = parseInt;
if (c0.length > 7) {
var f = c0.split(","), t = (c1 ? c1 : p < 0 ? "rgb(0,0,0)" : "rgb(255,255,255)").split(","), R = w(f[0].slice(4)), G = w(f[1]), B = w(f[2]);
return "rgb(" + (u((w(t[0].slice(4)) - R) * n) + R) + "," + (u((w(t[1]) - G) * n) + G) + "," + (u((w(t[2]) - B) * n) + B) + ")"
} else {
var f = w(c0.slice(1), 16), t = w((c1 ? c1 : p < 0 ? "#000000" : "#FFFFFF").slice(1), 16), R1 = f >> 16, G1 = f >> 8 & 0x00FF, B1 = f & 0x0000FF;
return "#" + (0x1000000 + (u(((t >> 16) - R1) * n) + R1) * 0x10000 + (u(((t >> 8 & 0x00FF) - G1) * n) + G1) * 0x100 + (u(((t & 0x0000FF) - B1) * n) + B1)).toString(16).slice(1)
}
}

var colors = [
"#d35400",
"#c0392b",
"#2980b9",
"#7f8c8d"
];

angular.module('starter.controllers', [])
.controller('homeCtrl', function ($scope, $state) {
console.log('in home');
$scope.start = function () {
Expand Down Expand Up @@ -64,14 +81,11 @@ angular.module('starter.controllers', [])
};
$scope.choosePersona = function (persona) {
if (persona === 'student') {

engine.pockets.create(student).then(function () {
$state.go('tab.pockets');
}).error(function (err) {
if (err) console.log(err);
if (err) throw err;
});

//$state.go('tab.pockets');
}
};
})
Expand All @@ -87,81 +101,61 @@ angular.module('starter.controllers', [])
$scope.pocketName = 'root';

engine.pockets.get({name: $scope.pocketName}).then(function (result) {
var currentColor = result.color;
var i = 1;

for (var k in result.pockets) {
if (result.pockets.hasOwnProperty(k)) {
if (!result.pockets[k].color && result.pockets[k] != 'root')
result.pockets[k].color = shadeBlend(i / 10, currentColor);
}
i++;
}

$scope.pockets = result;
console.log(result);
}).error(function (err) {
if (err)
throw err;
});

/*
$scope.pockets = {
parent: null,
name: 'root',
pockets: {
savings: {
parent: 'root',
name: 'Savings',
hard_ratio: 0.33,
color: '#8e44ad',
pockets: {
house: {
name: 'House',
parent: 'savings',
hard_ratio: 0.7
},
tv: {
name: 'TV',
parent: 'savings',
hard_ratio: 0.3
}
}
},
spending: {
parent: 'root',
name: 'Spending',
hard_ratio: 0.333,
color: '#2c3e50',
pockets: {
'shopping': {
parent: 'spending',
name: 'shopping',
hard_ratio: 0.4
},
'cigarettes': {
parent: 'spending',
name: 'cigarettes',
hard_ratio: 0.3
},
rent: {
parent: 'spending',
name: 'Rent',
hard_ratio: 0.3
}
}
},
testing: {
parent: 'root',
color: '#cccccc',
name: 'testing',
hard_ratio: 0.333
}
}
};
*/

$scope.selectPocket = function (pocketName, hasChildren) {
if (hasChildren)
$state.go('tab.pockets', {pocketName: pocketName});
else
$state.go('tab.pocket-details', {pocketName: pocketName});
};
$scope.pocketHold = function (pocketName) {
var myPopup = $ionicPopup.alert({
template: "<div>Delete?</div>",
scope: $scope,
buttons: [
{text: 'Cancel'},
{
text: '<b>Delete</b>',
type: 'button-positive',
onTap: function () {
return true
}
}
]
});
myPopup.then(function (res) {
if (res) {
engine.pockets.delete({name: pocketName}).then(function () {

});
}
});
};
$scope.addPocket = function () {
$scope.newpocket = {};
var myPopup = $ionicPopup.show({
template: '<div class="list">' +
'<label class="item item-input item-select">' +
'<span class="input-label">Parent</span>' +
'<select ng-model="newpocket.parent">' +
'<option value="root">root</option>' +
'<option ng-repeat="(key, pocket) in pockets.pockets" value="{{pocket.name}}">{{pocket.name}}</option>' +
'</select>' +
'</label>' +
Expand All @@ -171,7 +165,11 @@ angular.module('starter.controllers', [])
'</label>' +
'<label class="item item-input">' +
'<span class="input-label">Ratio</span>' +
'<input ng-model="newpocket.ratio" type="number" placeholder="20">' +
'<input ng-model="newpocket.hard_ratio" type="number" placeholder="20">' +
'</label>' +
'<label class="item item-input">' +
'<span class="input-label">Color</span>' +
'<input ng-model="newpocket.color" type="text" placeholder="#cccccc">' +
'</label>' +
'<label class="item item-input item-select">' +
'<span class="input-label">Importance</span>' +
Expand Down Expand Up @@ -204,18 +202,65 @@ angular.module('starter.controllers', [])
]
});
myPopup.then(function (res) {
$scope.newpocket.hard_ratio = $scope.newpocket.hard_ratio / 100;
engine.pockets.create($scope.newpocket).then(function () {
//$state.go('')
}).error(function (err) {
if (err)
throw err;
});
});
}
})
.controller('pocketDetailsCtrl', function ($scope, $state, $stateParams) {
$
};
$scope.rootInfo = function () {
var myPopup = $ionicPopup.show({
template: '<div>QR</div>',
title: 'Info',
scope: $scope,
buttons: [
{
text: '<b>OK</b>',
type: 'button-positive'
}
]
});
myPopup.then(function (res) {

});
};
})
.controller('pocketDetailsCtrl', function ($scope, $state, $ionicPopup, $stateParams, $cordovaBarcodeScanner) {
engine.pockets.get({name: $stateParams.pocketName}).then(function (result) {
$scope.pockets = result;
$scope.$digest();
});
$scope.scanQR = function () {
$cordovaBarcodeScanner.scan().then(function (imageData) {
$scope.toAddress = imageData.text;
}, function (error) {
console.log("An error happened -> " + error);
});
};
$scope.spendDialog = function () {
$scope.data = {};
var myPopup = $ionicPopup.show({
template: '<label class="item item-input">' +
'<span class="input-label">Amount</span>' +
'<input ng-model="data.amount" type="number" placeholder="0.01">' +
'</label>' +
'<br><div ng-click="scanQR()">Scan</div><br><button class="btn btn-danger">Send</button>',
title: 'Info',
scope: $scope,
buttons: [
{
text: '<b>OK</b>',
type: 'button-positive'
}
]
});
myPopup.then(function (res) {
console.log($scope.pockets.name, $scope.toAddress, $scope.amount);
});
};
})
.controller('DashCtrl', function ($scope) {
})
Expand Down
18 changes: 18 additions & 0 deletions www/js/directives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
angular.module('starter.directives', [])
.directive('qrcode', function () {
function link(scope, element, attrs) {
var handled = false;
scope.$watch(function() {
if (scope.pockets && !handled) {
handled = true;
new QRCode(document.getElementById("qrcode"), scope.pockets.wallet.address);
}
});
}
return {
restrict: 'E',
template: '<div id="qrcode"></div>',
link: link,
scope: "="
};
});
9 changes: 9 additions & 0 deletions www/js/ng-cordova.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions www/js/qrcode.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions www/templates/tab-pocket-details.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ion-view view-title="{{pocketName}}">
<ion-content class="padding">
<div style="text-align:center;padding-top:50px;">
QR
<button class="btn btn-lg btn-danger button-positive" ng-click="start()">SPEND</button>
<qrcode></qrcode><br>
<button class="btn btn-lg btn-danger button-positive" ng-click="spendDialog()">SPEND</button>
</div>
</ion-content>
</ion-view>
15 changes: 11 additions & 4 deletions www/templates/tab-pockets.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
<ion-view view-title="My pockets">
<ion-content>
<div class="pocket-content">
<div ng-repeat="(key, value) in pockets.pockets" ,
style="background-color:{{value.color}};width:100%;height:{{value.hard_ratio*100}}%; position:relative;" ng-click="selectPocket('{{value.name}}', '{{value.pockets}}')">
<div on-hold="pocketHold('{{value.name}}')" ng-repeat="(key, value) in pockets.pockets"
style="background-color:{{value.color}};width:100%;height:{{value.hard_ratio*100}}%; position:relative;"
ng-click="selectPocket('{{value.name}}', '{{value.pockets}}')">
<div class="pocket-title" style="background-color:{{value.color}}">
{{value.name}}
</div>
<div ng-if="value.pockets" style="height:100%">
<div class="children" ng-repeat="(subkey, subpocket) in value.pockets" style="height:100%;width:{{subpocket.hard_ratio*100}}%;border-right:1px solid #000"></div>
<div class="children" ng-repeat="(subkey, subpocket) in value.pockets"
style="height:100%;width:{{subpocket.hard_ratio*100}}%;border-right:1px solid #000"></div>
</div>
</div>
</div>
</ion-content>
<div style="position:absolute;top:50px; right: 8px;">
<button type="button" ng-click="rootInfo()" class="btn btn-primary btn-rootinfo btn-circle btn-lg"><i
class="fa fa-info"></i></button>
</div>
<div style="position:absolute;bottom:8px; right: 8px;">
<button type="button" ng-click="addPocket()" class="btn btn-primary btn-addpocket btn-circle btn-lg"><i class="fa fa-plus"></i></button>
<button type="button" ng-click="addPocket()" class="btn btn-primary btn-addpocket btn-circle btn-lg"><i
class="fa fa-plus"></i></button>
</div>
<div style="position:absolute;bottom:8px; left: 8px;">
<button type="button" class="btn btn-primary btn-spend btn-circle btn-lg"><i class="fa fa-bitcoin"></i></button>
Expand Down

0 comments on commit 0239293

Please sign in to comment.