-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_ctl.js
More file actions
95 lines (81 loc) · 2.75 KB
/
Copy pathapp_ctl.js
File metadata and controls
95 lines (81 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*globals angular, document, JST, window, _ */
angular.module('app')
.controller('appCtl', ['$scope', 'dataModel', function ($scope, dataModel) {
'use strict';
var dm;
function reset() {
$scope.target_model_name = $scope.attr = $scope.val = null;
}
$scope.init = function () {
dm = dataModel;
dm.init();
$scope.models_names = [];
$scope.loadExample();
};
$scope.loadExample = function () {
var cat;
$scope.models_names.push('cats');
$scope.models_names.push('cat_owners');
dm.initModelByName('cats');
_.each(['m', 'p', 'k', 't', 'b', 'z', 'v', 'l'], function (letter, i) {
cat = {
id: i,
name: letter + 'itzi',
color: Math.random() > 0.5 ? 'black' : 'white',
owner_id: Math.random() > 0.5 ? 1 : 2,
};
dm.addToModel('cats', cat);
});
dm.initModelByName('cat_owners');
var owner_1 = {id: 1, name: 'PAPA'};
var owner_2 = {id: 2, name: 'MAMA'};
dm.addToModel('cat_owners', owner_1);
dm.addToModel('cat_owners', owner_2);
};
$scope.createModel = function () {
if ($scope.target_model_name) {
dm.initModelByName($scope.target_model_name);
$scope.models_names.push($scope.target_model_name);
reset();
}
};
$scope.getModelByName = function (name) {
return dm.getModelByName(name).data;
};
$scope.addToModel = function () {
if ($scope.target_model_name && $scope.attr) {
var obj = {};
obj[$scope.attr] = $scope.val;
dm.addToModel($scope.target_model_name, obj);
}
reset();
};
$scope.groupModelByAttr = function () {
if ($scope.target_model_name && $scope.attr) {
$scope.group = dm.groupModelByAttr($scope.target_model_name, $scope.attr);
}
reset();
};
$scope.filterModelByAttrAndValue = function () {
if ($scope.target_model_name && $scope.attr) {
$scope.filtered_with_val = dm.filterModelByAttrAndValue($scope.target_model_name, $scope.attr, $scope.val);
}
reset();
};
$scope.filterModelByAttr = function () {
if ($scope.target_model_name && $scope.attr) {
$scope.filtered = dm.filterModelByAttr($scope.target_model_name, $scope.attr, $scope.val);
}
reset();
};
$scope.filterModelByAttrAndValuesArray = function () {
if ($scope.target_model_name && $scope.attr) {
var arr = $scope.val.split(',');
$scope.filtered_with_val_arr = dm.filterModelByAttrAndValuesArray($scope.target_model_name, $scope.attr, arr);
}
reset();
};
$scope.joinView = function () {
$scope.joined_view = dm.joinView('cats', 'cat_owners', 'owner_', ['owner_id', 'id']);
};
}]);