Skip to content

Commit

Permalink
redraw pie on sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammed Haque committed Jun 29, 2018
1 parent cf1b861 commit dacfcfe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
3 changes: 2 additions & 1 deletion static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.controller("mainCtrl", function ($scope, $rootScope, $location, $cookies, $t
$rootScope.sort = (() => {
let lastProp;
let asc = true;
return (prop, arr) => {
return (prop, arr, cb) => {
if (lastProp != prop) {
lastProp = prop;
asc = false;
Expand All @@ -32,6 +32,7 @@ app.controller("mainCtrl", function ($scope, $rootScope, $location, $cookies, $t
}
return comp * (asc ? 1 : -1);
});
if (cb) cb();
};
})();

Expand Down
8 changes: 4 additions & 4 deletions static/types/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ app.controller("typesCtrl", function ($scope, centsa) {
$scope.types = [];
centsa.types.getAll().then(resp => {
$scope.types = resp.data;
drawPie();
$scope.drawPie();
});

$scope.newType = {
Expand All @@ -15,7 +15,7 @@ app.controller("typesCtrl", function ($scope, centsa) {
$scope.newType.sum = 0;
$scope.types.unshift($scope.newType);
$scope.newType = Object.assign({}, newType);
drawPie();
$scope.drawPie();
});

$scope.deleteType = async id => {
Expand All @@ -31,12 +31,12 @@ app.controller("typesCtrl", function ($scope, centsa) {
if(result.value) {
centsa.types.remove(id).then(() => {
$scope.types.splice($scope.types.findIndex(t => t.id == id), 1);
drawPie();
$scope.drawPie();
});
}
};

const drawPie = () => {
$scope.drawPie = () => {
console.log('draw pie');
AmCharts.makeChart("types-chart", {
type: "pie",
Expand Down
69 changes: 34 additions & 35 deletions static/types/view.html
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
<div id="types-view">
<form name="Form" data-ng-submit="saveType()">
<h4>Manage types</h4>
<table id="typesTable" class="table table-condensed table-hover">
<thead>
<tr>
<th width="5%" data-ng-click="sort('id', types)">ID</th>
<th data-ng-click="sort('name', types)">Name</th>
<th colspan="2" data-ng-click="sort('sum', types)">Sum</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>
<input type="text" class="form-control" required="required" data-ng-model="newType.name">
</td>
<td></td>
<td>
<input type="submit" value="Save" class="btn btn-primary" data-ng-class="{ 'btn-warning': Form.$invalid }" data-ng-disabled="Form.$invalid">
</td>
</tr>
<tr data-ng-repeat="t in types" data-ng-click="setFilter({type_id:t.id.toString()})">
<td>{{ t.id }}</td>
<td>{{ t.name }}</td>
<td>{{ t.sum/100 }}</td>
<td colspan="2">
<a href="" data-ng-click="deleteType(t.id);$event.stopPropagation()">Delete</a>
</td>
</tr>
</tbody>
</table>
</form>
<div id="chart"></div>
<form name="Form" data-ng-submit="saveType()">
<h4>Manage types</h4>
<table id="typesTable" class="table table-condensed table-hover">
<thead>
<tr>
<th width="5%" data-ng-click="sort('id', types, drawPie)">ID</th>
<th data-ng-click="sort('name', types, drawPie)">Name</th>
<th colspan="2" data-ng-click="sort('sum', types, drawPie)">Sum</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>
<input type="text" class="form-control" required="required" data-ng-model="newType.name">
</td>
<td></td>
<td>
<input type="submit" value="Save" class="btn btn-primary" data-ng-class="{ 'btn-warning': Form.$invalid }" data-ng-disabled="Form.$invalid">
</td>
</tr>
<tr data-ng-repeat="t in types" data-ng-click="setFilter({type_id:t.id.toString()})">
<td>{{ t.id }}</td>
<td>{{ t.name }}</td>
<td>{{ t.sum/100 }}</td>
<td colspan="2">
<a href="" data-ng-click="deleteType(t.id);$event.stopPropagation()">Delete</a>
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div id="types-chart"></div>
<div id="types-chart"></div>

0 comments on commit dacfcfe

Please sign in to comment.