-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsequences.js
108 lines (90 loc) · 3.19 KB
/
sequences.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
api.factory('Sequence', ["SQLClient", function (SQLClient) {
return function (sequenceFromDB) {
angular.extend(this, sequenceFromDB);
};
}]);
cdbmanager.service("sequences", ["SQLClient", "Sequence", function (SQLClient, Sequence) {
let self = this;
this.api = new SQLClient();
this.tmp_api = new SQLClient();
let getSequenceDetails = function (results) {
self.api.items.push(new Sequence(results.data.rows[0]));
};
this.get = function (action, error, extraQuery) {
let _action = function () {
if (self.api && self.api.items) {
let itemsCopy = angular.copy(self.api.items);
self.api.items = [];
for (let i = 0; i < itemsCopy.length; i++) {
let query = "select * from " + itemsCopy[i].relname;
self.tmp_api.send(query, getSequenceDetails);
}
}
if (action) {
action();
}
};
let query = "select pg_class.relname from pg_class, pg_roles, pg_namespace where pg_roles.oid = pg_class.relowner and pg_roles.rolname = current_user and pg_namespace.oid = pg_class.relnamespace and pg_class.relkind = 'S'";
if (extraQuery) {
query += " " + extraQuery;
}
self.api.send(query, _action, error);
};
this.orderName = "desc";
this.order = function (parameter, orderName) {
if (self.orderName == "asc") {
self.orderName = "desc";
self.api.items.sort(function (a, b) {
if (a[parameter] > b[parameter]) return -1;
if (a[parameter] < b[parameter]) return 1;
return 0;
});
} else {
self.orderName = "asc";
self.api.items.sort(function (a, b) {
if (a[parameter] < b[parameter]) return -1;
if (a[parameter] > b[parameter]) return 1;
return 0;
});
}
};
}]);
cdbmanager.controller('sequenceSelectorCtrl', ["$scope", "sequences", "endpoints", "nav", function ($scope, sequences, endpoints, nav) {
$scope.nav = nav;
$scope.refreshList = function () {
sequences.get();
};
// update sequence list in scope when current endpoint changes
$scope.$watch(function () {
return endpoints.current;
}, function () {
$scope.sequences = $scope.refreshList();
}, true);
// update sequence list in scope when actual sequence list changes
$scope.$watch(function () {
return sequences.api.items;
}, function (sequenceList) {
$scope.sequences = sequenceList;
});
}]);
cdbmanager.controller('sequenceCtrl', ["$scope", "nav", "sequences", "columns", "indexes", "triggers", "constraints", "records", "endpoints", "settings", function ($scope, nav, sequences, columns, indexes, triggers, constraints, records, endpoints, settings) {
$scope.nav = nav;
// Settings for the result tables
$scope.cdbrt = {
id: "sequences",
rowsPerPage: settings.rowsPerPage,
orderBy: sequences.order
};
// update number of rows per page when settings changes
$scope.$watch(function () {
return settings.rowsPerPage;
}, function () {
$scope.cdbrt.rowsPerPage = settings.rowsPerPage;
});
// update sequence list in scope when actual sequence list changes
$scope.$watch(function () {
return sequences.api.items;
}, function (sequenceList) {
$scope.sequences = sequenceList;
});
}]);