Commit 67aeaf4e5fedcaca23c45f1cf0869380941588a3

Authored by Tarpit Grover
1 parent 6e6aa9b0
Exists in master

commit

Showing 56 changed files with 2153 additions and 2153 deletions   Show diff stats
common_components/directives/BindHtmlCompile.directive.js
... ... @@ -1,21 +0,0 @@
1   -(function (angular) {
2   - 'use strict';
3   -
4   - var module = angular.module('framework.directives.utils', []);
5   -
6   - module.directive('bindHtmlCompile', ['$compile', bindHtmlCompile]);
7   -
8   - function bindHtmlCompile($compile) {
9   - return {
10   - restrict: 'A',
11   - link: function (scope, element, attrs) {
12   - scope.$watch(function () {
13   - return scope.$eval(attrs.bindHtmlCompile);
14   - }, function (value) {
15   - element.html(value);
16   - $compile(element.contents())(scope);
17   - });
18   - }
19   - };
20   - }
21   -}(angular));
22 0 \ No newline at end of file
common_components/directives/Card.directive.js
... ... @@ -1,48 +0,0 @@
1   -(function(angular){
2   - var module = angular.module('framework.directives.UI',[]);
3   -
4   - module.directive('card', cardDirective);
5   - cardDirective.$inject=['$state', '$interval', '$parse'];
6   - function cardDirective($state, $interval, $parse) {
7   - return {
8   - restrict: 'E',
9   - transclude: true,
10   - replace: true,
11   - scope: true,
12   - template: function(element, attrs) {
13   - var template='';
14   - template += '<div class="card"><div class="card-container"';
15   - if(attrs.allowClick!="false") {
16   - template += ' ng-click="viewItem(item)"'
17   - }
18   - template += '><svg class="logo" style="background-image:url(\'{{::accessors.LogoUrl(item)}}\')" viewBox="0 0 100 100"><circle cx="50" cy="50" r="50" fill="transparent" stroke-width="10" stroke-linecap="round" ng-show="showScore==true" stroke-location="outside"></circle></svg>';
19   - if(attrs.showTitle!="false") {
20   - template += '<strong>{{ ::accessors.Title(item) }}</strong>';
21   - }
22   - if(attrs.showSubtitle!="false") {
23   - template += '<small>{{ ::accessors.SubTitle(item) }}</small>';
24   - }
25   - template += '</div></div>';
26   - return template;
27   - },
28   - link: function(scope, elem, attrs, ctrls, transcludeFn) {
29   - if(attrs.item) {
30   - var getter = $parse(attrs.item);
31   - scope.item = getter(scope);
32   - }
33   - scope.viewItem = viewItem;
34   - if(scope.accessors.Score) {
35   - var percentScore = (2 * Math.PI*50)/100*scope.accessors.Score(scope.item);
36   - var percentColor = (percentScore < 90)? 'red': (percentScore >= 90 && percentScore <180)? 'orange' :(percentScore >= 180 && percentScore <270)? 'rgb(25, 195, 45)' : 'rgb(25, 195, 45);';
37   - elem.find("circle")
38   - .attr("stroke", percentColor)
39   - .attr("stroke-dasharray",percentScore+",10000");
40   - }
41   -
42   - function viewItem(item) {
43   - $state.go(scope.rNavTo, { Id: item.Id });
44   - }
45   - }
46   - }
47   - }
48   -})(angular);
49 0 \ No newline at end of file
common_components/directives/FieldFor.directive.js
... ... @@ -1,218 +0,0 @@
1   -(function (angular) {
2   - var module = angular.module('framework.directives.UI');
3   -
4   - module.directive('fieldFor', fieldForDirective);
5   - module.directive('formFor', formForDirective);
6   - module.filter('propSearch', propertySearchFilter);
7   -
8   - formForDirective.$inject = ['Model'];
9   - function formForDirective(Model) {
10   - return {
11   - restrict: 'A',
12   - scope: true,
13   - transclude: true,
14   - template: function (element, attrs) {
15   - return '<form name="formFor.form" class="transclude-target" autocomplete="off" novalidate></form>';
16   - },
17   - link: function (scope, element, attrs, ctrls, transcludeFn) {
18   - scope.formFor = (scope.formFor || {});
19   - scope.formFor.target = scope.$eval(attrs.formFor);
20   - scope.formFor.schema = (attrs.schema) ? Model[attrs.schema].$schema : scope.target.$$schema;
21   - scope.formFor.mode = 'EDIT';
22   -
23   - scope.$watch(function () {
24   - return scope.target;
25   - }, function (newvalue) {
26   -
27   - });
28   -
29   - if (attrs.mode) {
30   - scope.formFor.mode = attrs.mode;
31   - attrs.$observe('mode', function (newvalue) {
32   - scope.formFor.mode = newvalue;
33   - });
34   - }
35   -
36   - transcludeFn(scope, function (clone, scope) {
37   - element.children('.transclude-target').append(clone);
38   - });
39   - }
40   - }
41   - };
42   -
43   - fieldForDirective.$inject = ['Model'];
44   - function fieldForDirective(Model) {
45   - var defaults = {
46   - inputType: 'text',
47   - required: false,
48   - selectTheme: 'selectize',
49   - selectSelectedTemplate: '{{$select.selected.Name}}',
50   - selectOptionTemplate: '<div ng-bind-html="option.Name | highlight: $select.search"></div><small class="text-muted">{{option.Description}}</small>'
51   - };
52   - return {
53   - restrict: 'A',
54   - scope: true,
55   - template: function (element, attrs) {
56   - var formParent = element.closest('[form-for]'),
57   - subformParent = element.closest('[sub-form-for]'),
58   - schemaName = ((subformParent.length) ? subformParent : formParent).attr('schema'),
59   - ctor = Model[schemaName],
60   - schema = ctor && ctor.$schema,
61   - fieldDef = schema && schema[attrs.fieldFor],
62   - subForm = subformParent.attr('sub-form-for') || '';
63   -
64   - if (!fieldDef) {
65   - return;
66   - }
67   -
68   - var inputConfig = angular.extend({ display: attrs.fieldFor, inputType: 'text' }, defaults, fieldDef, fieldDef.input, attrs);
69   -
70   - //need to fetch these.
71   - var labelText = attrs.display || attrs.fieldFor,
72   - fieldName = attrs.fieldFor,
73   - selectFrom = attrs.selectFrom;
74   -
75   - var template = '' +
76   - '<div class="form-group">' +
77   - '<label class="control-label" for="' + subForm + fieldName + 'Input">' + inputConfig.display + '</label>' +
78   - '<div ng-if="formFor.mode === \'VIEW\'">' +
79   - '<p class="form-control-static" ng-bind="::formFor.target.' + ((subForm) ? (subForm + '.') : '') + (inputConfig.displayField ? inputConfig.displayField : fieldName) + (inputConfig.displayFilters ? inputConfig.displayFilters : '') + '"></p>' +
80   - '</div>' +
81   - '<div ng-if="formFor.mode === \'EDIT\'">';
82   -
83   - if (selectFrom) {
84   - template += '' +
85   - '<ui-select ng-model="formFor.target.' + ((subForm) ? (subForm + '.') : '') + fieldName + '" name="' + subForm + fieldName + 'Input" theme="' + inputConfig.selectTheme + '" ng-disabled="' + (angular.isDefined(inputConfig.editable) && !inputConfig.editable) + '" ng-required="' + inputConfig.required + '">' +
86   - '<ui-select-match allow-clear="true" placeholder="' + (inputConfig.placeholder || 'Select..') + '">' + inputConfig.selectSelectedTemplate + '</ui-select-match>' +
87   - '<ui-select-choices repeat="option.Id as option in ' + selectFrom + ' | propSearch: { Name: $select.search }">' +
88   - inputConfig.selectOptionTemplate +
89   - '</ui-select-choices>'+
90   - '</ui-select>';
91   - } else if (inputConfig.type === moment) {
92   - template += '' +
93   - '<div class="input-group">' +
94   - buildElement('input', {
95   - class: 'form-control',
96   - type: 'text',
97   - name: subForm + fieldName + 'Input',
98   - ngModel: 'formFor.target.' + ((subForm) ? (subForm + '.') : '') + fieldName,
99   - ngRequired: inputConfig.required,
100   - datepickerPopup: 'dd/MM/yyyy',
101   - isOpen: 'opened',
102   - placeholder: 'DD/MM/YYYY',
103   - ngDisabled: angular.isDefined(inputConfig.editable) && !inputConfig.editable
104   - }) +
105   - '<span class="input-group-btn">' +
106   - '<button type="button" class="btn btn-default" ng-click="openCalendar($event)"><i class="glyphicon glyphicon-calendar"></i></button>' +
107   - '</span>' +
108   - '</div>';
109   - } else {
110   - if (inputConfig.append || inputConfig.prepend) {
111   - template += '<div class="input-group">';
112   - }
113   - if (inputConfig.prepend) {
114   - template += '<span class="input-group-btn">' +
115   - '<button type="button" class="btn btn-default" ng-click="' + inputConfig.prepend.click + '"><i class="' + inputConfig.prepend.icon + '"></i>' + inputConfig.prepend.text + '</button>' +
116   - '</span>'
117   - }
118   - template += buildElement('input', {
119   - class: 'form-control',
120   - type: inputConfig.inputType,
121   - name: subForm + fieldName + 'Input',
122   - ngModel: 'formFor.target.' + ((subForm) ? (subForm + '.') : '') + fieldName,
123   - ngRequired: inputConfig.required,
124   - placeholder: inputConfig.placeholder
125   - });
126   - if (inputConfig.append) {
127   - template += '<span class="input-group-btn">' +
128   - '<button type="button" class="btn btn-default" ng-click="' + inputConfig.append.click + '"><i class="' + inputConfig.append.icon + '"></i>' + inputConfig.append.text + '</button>' +
129   - '</span>'
130   - }
131   - if (inputConfig.append || inputConfig.prepend) {
132   - template += '</div>';
133   - }
134   - }
135   -
136   - template += '' +
137   - '<div ng-messages="formFor.form.' + subForm + fieldName + 'Input.$error" class="help-block">' +
138   - '<div ng-message="required">' + inputConfig.display + ' is required.</div>' +
139   - '<div ng-message="parse">' + inputConfig.display + ' is incorrectly formatted.</div>' +
140   - '<div ng-message="email">' + inputConfig.display + ' is not a valid e-mail.</div>' +
141   - '</div>' +
142   - '</div>';
143   - template += '</div>';
144   - return template;
145   - },
146   - link: function (scope, element, attrs) {
147   - scope.opened = false;
148   -
149   - scope.openCalendar = function (event) {
150   - event.preventDefault();
151   - event.stopPropagation();
152   - scope.opened = true;
153   - }
154   - }
155   - };
156   - };
157   -
158   - function propertySearchFilter() {
159   - return function (items, props) {
160   - var out = [];
161   -
162   - if (angular.isArray(items)) {
163   - items.forEach(function (item) {
164   - var itemMatches = false;
165   -
166   - var keys = Object.keys(props);
167   - for (var i = 0; i < keys.length; i++) {
168   - var prop = keys[i];
169   - var text = props[prop].toLowerCase();
170   - if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
171   - itemMatches = true;
172   - break;
173   - }
174   - }
175   -
176   - if (itemMatches) {
177   - out.push(item);
178   - }
179   - });
180   - } else {
181   - // Let the output be the input untouched
182   - out = items;
183   - }
184   -
185   - return out;
186   - };
187   - };
188   -
189   - function buildElement(elementType, attrs) {
190   - var result = '<' + elementType + ' ';
191   -
192   - angular.forEach(attrs, function (value, key) {
193   - if (angular.isDefined(value) && value !== null)
194   - result += normalise(key) + '="' + value + '"';
195   - });
196   -
197   - if (elementType === 'input') {
198   - result += ' />';
199   - } else {
200   - result += ' ></' + elementType + '>';
201   - }
202   - return result;
203   - }
204   -
205   - function normalise(input) {
206   - var result = '';
207   - for (var i = 0; i < input.length; i++) {
208   - var char = input[i];
209   - if (char == char.toUpperCase()) {
210   - result += '-' + char.toLowerCase();
211   - } else {
212   - result += char;
213   - }
214   - }
215   - return result;
216   - }
217   -
218   -}(angular));
219 0 \ No newline at end of file
common_components/directives/Score.directive.js
... ... @@ -1,53 +0,0 @@
1   -(function(angular){
2   - var module = angular.module('framework.directives.UI');
3   -
4   - module.directive('score', scoreDirective);
5   -
6   - scoreDirective.$inject=['$state', '$interval', '$parse'];
7   -
8   - function scoreDirective($state, $interval, $parse) {
9   - return {
10   - restrict: 'E',
11   - transclude: true,
12   - replace: true,
13   - scope: true,
14   - template: function(element, attrs) {
15   - var template='';
16   - template += '<div class="score"';
17   - if(attrs.size) {
18   - var scoreSize = parseInt(attrs.size);
19   - template += ' style="position:relative;width:'+ (scoreSize) +'px; height: ' + (scoreSize) + 'px; border-radius:'+ (scoreSize/2) + 'px;padding:5px;">';
20   - }
21   - else {
22   - template += ' style="width:100px;height:100px;border-radius:50px;">';
23   - }
24   - if(attrs.showScore) {
25   - template += '<div class="score-value" style="line-height:' + scoreSize + 'px">'+attrs.showScore+'</div>';
26   - }
27   - template += '<svg class="dial" viewBox="0 0 100 100">' +
28   - '<circle class="score-back-circle" cx="50" cy="50" r="45" fill="transparent" stroke-linecap="round"></circle>' +
29   - '<circle class="score-front-circle" cx="50" cy="50" r="45" fill="transparent" stroke-linecap="round"></circle>' +
30   - '</svg>';
31   - template += '</div>';
32   - return template;
33   - },
34   - link: function(scope, elem, attrs, ctrls, transcludeFn) {
35   - if(!attrs.value)
36   - return;
37   -
38   - var strokeWidth = (attrs.strokeWidth)? attrs.strokeWidth : 5;
39   - var percentScore = (2 * Math.PI*50)/100 * attrs.value;
40   - var percentColor = (percentScore < 90)? 'red': (percentScore >= 90 && percentScore <180)? 'orange' :(percentScore >= 180 && percentScore <270)? 'rgb(25, 195, 45)' : 'rgb(25, 195, 45)';
41   -
42   - elem.find("circle.score-back-circle")
43   - .attr("stroke", "#eee")
44   - .attr("stroke-width", strokeWidth);
45   -
46   - elem.find("circle.score-front-circle")
47   - .attr("stroke", percentColor)
48   - .attr("stroke-width", strokeWidth)
49   - .attr("stroke-dasharray", percentScore+",10000");
50   - }
51   - }
52   - }
53   -})(angular);
54 0 \ No newline at end of file
common_components/directives/TableFor.directive.js
... ... @@ -1,592 +0,0 @@
1   -(function (angular) {
2   - var module = angular.module('framework.directives.UI');
3   -
4   - module.directive('tableFor', tableForDirective);
5   - module.directive('tableTitlebar', tableTitlebarDirective);
6   - module.directive('tableHeading', tableHeadingDirective);
7   - module.directive('tableDataRows', tableDataRowsDirective);
8   - module.directive('tableFooter', tableFooterDirective);
9   - module.filter('publish', publishFilter);
10   - module.filter('softFilter', softFilter);
11   - module.filter('pageGroup', pageGroupFilter);
12   -
13   -
14   -
15   - tableForDirective.$inject = ['$parse', 'Model', '$modal', '$q', '$filter', '$timeout'];
16   - function tableForDirective($parse, Model, $modal, $q, $filter, $timeout) {
17   - var defaults = {
18   - wrapperClass: 'table-responsive',
19   - tableClass: 'table table-bordered',
20   - minWidth: '600px'
21   - }
22   -
23   - function linkFn(scope, element, attrs, ctrls, transcludeFn) {
24   - var externalSearch = $parse(attrs.filtering)(scope);
25   - var externalSorting = $parse(attrs.sorting)(scope);
26   - var externalGrouping = $parse(attrs.grouping)(scope);
27   - var externalPaging = $parse(attrs.paging)(scope);
28   -
29   - scope.$schema = Model[attrs.schema].$schema;
30   - scope.$table = {
31   - actionColumn: false,
32   - selectionColumn: false,
33   - cardTemplate: '{{$row | json}}',
34   - toggleSelectAll: toggleSelectAll,
35   - toggleRowSelection: toggleRowSelection,
36   - toggleGroupSelection: toggleGroupSelection,
37   - allSelected: false,
38   - reset: reset,
39   - configureColumns: configureColumns,
40   - sort: sort,
41   - getSortingClass: getSortingClass
42   - };
43   - scope.$columns = generateColumns(scope.$schema);
44   - scope.$filtering = externalSearch || {
45   - $: ''
46   - }
47   - scope.$sorting = externalSorting || [];
48   - scope.$grouping = externalGrouping || {
49   - value: undefined
50   - };
51   - scope.$paging = externalPaging || {
52   - currentPage: 1,
53   - totalItems: 0,
54   - maxPerPage: 10
55   - };
56   - scope.$data = {}; //object as it's grouped
57   - scope.$datasource = function () {
58   - return arguments[4]; //returns existing data by default;
59   - };
60   -
61   - var datasource = $parse(attrs.datasource)(scope);
62   - if (angular.isArray(datasource)) {
63   - scope.$datasource = generateLocalDatasource(datasource);
64   - } else if (angular.isFunction(datasource)) {
65   - scope.$datasource = datasource;
66   - } else {
67   - scope.$datasource = generateModelDatasource(scope.$schema.query);
68   - }
69   -
70   - scope.$watchCollection(function () { return scope.$filtering; }, debouncedUpdateData);
71   - scope.$watchCollection(function () { return scope.$sorting; }, debouncedUpdateData);
72   - scope.$watchCollection(function () { return scope.$grouping; }, debouncedUpdateData);
73   - scope.$watch(function () { return scope.$paging.currentPage; }, debouncedUpdateData);
74   - scope.$watch(function () { return scope.$paging.maxPerPage; }, debouncedUpdateData);
75   -
76   - var updateDebounce = null;
77   -
78   - function debouncedUpdateData() {
79   - if (updateDebounce) {
80   - $timeout.cancel(updateDebounce);
81   - updateDebounce = null;
82   - }
83   - updateDebounce = $timeout(updateData, 500);
84   - }
85   -
86   - function updateData() {
87   - for (var key in scope.$data) {
88   - delete scope.$data[key];
89   - }
90   - scope.$data.$loading = true;
91   - scope.$data.$error = null;
92   - scope.$datasource(scope.$filtering, scope.$sorting, scope.$grouping, scope.$paging, scope.$data).then(dataReceived, dataError, dataNotified);
93   - }
94   -
95   - function dataReceived(data) {
96   - for (var key in scope.$data) {
97   - delete scope.$data[key];
98   - }
99   - scope.$data.$loading = false;
100   - angular.extend(scope.$data, data);
101   - }
102   -
103   - function dataError(error) {
104   - for (var key in scope.$data) {
105   - delete scope.$data[key];
106   - }
107   - scope.$data.$loading = false;
108   - scope.$data.$error = error;
109   - }
110   -
111   - function dataNotified(dataLength) {
112   - scope.$paging.totalItems = dataLength;
113   - }
114   -
115   - transcludeFn(scope, function (clone, scope) {
116   - element.find('table').append(clone);
117   - });
118   -
119   - function generateLocalDatasource(initialData) {
120   - var data = initialData;
121   - return function (filtering, sorting, grouping, paging, existing) {
122   - var deferred = $q.defer();
123   -
124   - setTimeout(function () {
125   - var filter = $filter('filter');
126   - var orderBy = $filter('orderBy');
127   - var groupBy = $filter('groupBy');
128   - var pageGroup = $filter('pageGroup');
129   -
130   - deferred.notify(filter(data, filtering).length);
131   -
132   - var amendedSorting = [grouping.value];
133   - [].push.apply(amendedSorting, sorting);
134   -
135   - var result = pageGroup(groupBy(orderBy(filter(data, filtering), amendedSorting), grouping.value), paging);
136   -
137   - deferred.resolve(result);
138   - }, 0);
139   -
140   - return deferred.promise;
141   - }
142   - }
143   -
144   - function generateModelDatasource(modelQuery) {
145   - var queryBase = modelQuery;
146   - return function (filtering, sorting, grouping, paging, existing) {
147   - var deferred = $q.defer();
148   -
149   - query = queryBase();
150   - if (grouping.value) {
151   - query.orderBy(grouping.value);
152   - }
153   -
154   - angular.forEach(ordering, function (o) { query.orderBy(o); });
155   -
156   -
157   - setTimeout(function () {
158   - var filter = $filter('filter');
159   - var groupBy = $filter('groupBy');
160   - var pageGroup = $filter('pageGroup');
161   -
162   - deferred.notify(filter(data, filtering).length);
163   -
164   - var amendedSorting = [grouping.value];
165   - [].push.apply(amendedSorting, sorting);
166   -
167   - var result = pageGroup(groupBy(orderBy(filter(data, filtering), amendedSorting), grouping.value), paging);
168   -
169   - deferred.resolve(result);
170   - }, 0);
171   -
172   - return deferred.promise;
173   - }
174   - }
175   -
176   - function generateColumns(modelSchema) {
177   - var columns = [];
178   - angular.forEach(modelSchema, function (value, key) {
179   - var config = angular.extend({}, value, value.table || {});
180   - if (config.hidden) {
181   - return;
182   - }
183   - if (!angular.isDefined(config.visible)) {
184   - config.visible = true;
185   - }
186   - if (!angular.isDefined(config.binding) && config.type === moment) {
187   - config.binding = key + ".toDate() | date:'dd/MM/yyyy'";
188   - }
189   - columns.push({ key: key, title: config.display || key, accessor: angular.isFunction(config.binding) ? config.binding : buildAccessor(config.binding || key), binding: config.binding || key, visible: config.visible, filters: config.filters });
190   - });
191   - return columns;
192   - }
193   -
194   - function toggleSelectAll() {
195   - scope.$table.allSelected = !scope.$table.allSelected;
196   - angular.forEach(scope.$data, function (group) {
197   - toggleGroupSelection(group, scope.$table.allSelected);
198   - });
199   - }
200   -
201   - function toggleRowSelection(group, row, force) {
202   - row.$selected = angular.isDefined(force) ? force : !row.$selected;
203   - var selected = group.filter(function (d) { return d.$selected; });
204   - group.$selected = selected.length === group.length;
205   -
206   - var groups = 0;
207   - var selectedGroups = 0;
208   - angular.forEach(scope.$data, function (group, title) {
209   - if (title[0] == '$') {
210   - return;
211   - }
212   - groups++;
213   - if (group.$selected) selectedGroups++;
214   - });
215   - scope.$table.allSelected = groups === selectedGroups;
216   - }
217   -
218   - function toggleGroupSelection(group, force) {
219   - if (angular.isDefined(force)) {
220   - group.$selected = force;
221   - } else {
222   - group.$selected = !group.$selected;
223   - }
224   - angular.forEach(group, function (row) {
225   - row.$selected = group.$selected;
226   - });
227   -
228   - if (!angular.isDefined(force)) {
229   - var groups = 0;
230   - var selectedGroups = 0;
231   - angular.forEach(scope.$data, function (group, title) {
232   - if (title[0] == '$') {
233   - return;
234   - }
235   - groups++;
236   - if (group.$selected) selectedGroups++;
237   - });
238   - debugger;
239   - scope.$table.allSelected = groups === selectedGroups;
240   - }
241   - }
242   -
243   - function setAreAllSelected() {
244   - scope.$table.allSelected = false;
245   - }
246   -
247   - function sort(col) {
248   - //multisort
249   - var currentSort = scope.$sorting[0];
250   - if (col == currentSort) {
251   - scope.$sorting[0] = '-' + col;
252   - } else if ('-' + col == currentSort) {
253   - scope.$sorting[0] = col;
254   - } else {
255   - scope.$sorting.length = 0;
256   - scope.$sorting.push(col);
257   - }
258   - }
259   -
260   - function getSortingClass(col) {
261   - if (col == scope.$sorting[0]) {
262   - return 'icon-Arrow-Down2 brand-primary';
263   - }
264   - else if ('-' + col == scope.$sorting[0]) {
265   - return 'icon-Arrow-Up2 brand-primary';
266   - } else {
267   - return 'icon-Arrow-Down';
268   - }
269   - }
270   -
271   - function reset() {
272   - scope.$filtering = externalSearch || {
273   - $: ''
274   - }
275   - scope.$sorting = [];
276   -
277   - //TODO: Deselect ALL
278   -
279   - scope.$columns.length = 0;
280   - [].push.apply(scope.$columns, generateColumns(scope.$schema));
281   - }
282   -
283   - function buildAccessor(fieldName) {
284   - console.log('return row.' + fieldName + ';');
285   - window.count = window.count || 0;
286   - return new Function('row', 'return row.' + fieldName + ';');
287   - }
288   -
289   - function configureColumns() {
290   - $modal.open({
291   - template: '' +
292   - '<div class="modal-header">' +
293   - '<button class="close" type="button" ng-click="$close()"><i class="icon-Close"></i></button>' +
294   - '<h3 class="modal-title">Customize Columns</h3>' +
295   - '</div>' +
296   - '<div class="modal-body">' +
297   - '<div ng-repeat="column in columns">' +
298   - '<a ng-click="moveUp(column)" ng-hide="$first"><i class="icon-Arrow-UpinCircle brand-primary"></i></a>' +
299   - ' &nbsp; {{column.title}}' +
300   - ' &nbsp; <a ng-click="moveDown(column)" ng-hide="$last"><i class="icon-Arrow-DowninCircle brand-primary"></i></a>' +
301   - '<div class="checkbox pull-right m0">' +
302   - '<input type="checkbox" id="columncustomise{{::$index}}" ng-model="column.visible" ng-checked="column.visible" />' +
303   - '<label for="columncustomise{{::$index}}"></label>' +
304   - '</div><br class="clearfix">' +
305   - '</div>' +
306   - '</div>',
307   - controller: function ($scope, columns) {
308   - $scope.columns = columns;
309   - $scope.moveUp = function (column) {
310   - var index = $scope.columns.indexOf(column);
311   - move(index, index - 1);
312   - }
313   - $scope.moveDown = function (column) {
314   - var index = $scope.columns.indexOf(column);
315   - move(index, index + 1);
316   - }
317   -
318   - function move(old_index, new_index) {
319   - $scope.columns.splice(new_index, 0, $scope.columns.splice(old_index, 1)[0]);
320   - }
321   - },
322   - size: 'sm',
323   - resolve: {
324   - columns: function () {
325   - return scope.$columns
326   - }
327   - }
328   - });
329   - }
330   - }
331   -
332   - function compileFn(element, attrs) {
333   - return linkFn;
334   - }
335   -
336   - return {
337   - scope: true,
338   - transclude: true,
339   - template: function (element, attrs) {
340   - return '<div class="' + (attrs.wrapperClass || defaults.wrapperClass) + '"><table class="' + (attrs.tableClass || defaults.tableClass) + ' module-table" style="min-width:' + (attrs.minWidth || defaults.minWidth) + '"></table></div>'
341   - },
342   - compile: function (element, attrs) {
343   - return linkFn;
344   - }
345   - };
346   - }
347   -
348   - function tableTitlebarDirective() {
349   - return {
350   - restrict: 'E',
351   - scope: true,
352   - replace: true,
353   - template: function (element, attrs) {
354   - var template = '' +
355   - '<thead><tr><th colspan="100" class="table-arrange">';
356   - if (attrs.title) {
357   - template += '<h3 class="table-title">' + attrs.title + '</h3>';
358   - }
359   - if (attrs.showCount) {
360   - template += '<h3 class="table-title brand-primary">({{$visible.length}} / {{ $data.length }})</h3>';
361   - }
362   - if (attrs.columnsOptions) {
363   - template += '<div class="columns-options">' +
364   - '<a href="" ng-click="$table.reset()"><i class="icon-Reset"></i>Reset</a>' +
365   - '<a href="" ng-click="$table.configureColumns()"><i class="icon-Receipt-2"></i>Arrange</a>' +
366   - '</div>';
367   - }
368   - template += '<div class="pull-right">' +
369   - '<pagination class="pagination-sm" style="margin: 0;" total-items="$paging.totalItems" ng-model="$paging.currentPage" items-per-page="$paging.maxPerPage" boundary-links="true" max-size="5"></pagination>' +
370   - '</div>';
371   - if (attrs.search) {
372   - template += '<input type="text" class="form-control pull-right" style="width:300px" placeholder="Search.." ng-model="$filtering.$" />';
373   - }
374   - template += '</th></tr></thead>'
375   - return template;
376   - }
377   - }
378   - }
379   -
380   - function tableHeadingDirective() {
381   - var defaults = {
382   - }
383   - return {
384   - restrict: 'E',
385   - scope: true,
386   - replace: true,
387   - template: function (element, attrs) {
388   - var tmpl = '' +
389   - '<thead><tr>' +
390   - '<th ng-if="::$table.selectionColumn" style="width:40px;text-align:center;">' +
391   - '<div class="checkbox"><input type="checkbox" id="table-group-check" ng-click="$table.toggleSelectAll()" ng-checked="$table.allSelected"/><label for="table-group-check"></label></div>' +
392   -
393   - '</th>' +
394   - '<th ng-repeat="$column in $columns | filter: { visible: true }" class="module-table-head">' +
395   - '<div><i ng-class="$column.icon"></i> {{ ::$column.title }}' +
396   - '<span class="table-sort"><a href="" ng-click="$table.sort($column.key)"><i ng-class="$table.getSortingClass($column.key)"></i></a></span>' +
397   - '</div>' + //add filter and search menu
398   - '</th>' +
399   - '<th ng-if="::$table.actionColumn" style="text-align:center;">' +
400   - 'Actions' +
401   - '</th>' +
402   - '</tr>';
403   - tmpl += '</thead>';
404   - return tmpl;
405   - }
406   - };
407   - }
408   -
409   - tableDataRowsDirective.$inject = ['$parse', 'Model'];
410   - function tableDataRowsDirective($parse, Model) {
411   - return {
412   - restrict: 'E',
413   - scope: true,
414   - replace: true,
415   - template: function (element, attrs) {
416   - var tmp = '' +
417   - '<tbody ng-repeat="(title, group) in $data track by title">' +
418   - '<tr ng-hide="title == \'undefined\'">' +
419   - '<td ng-if="::$table.selectionColumn" style="width:40px;text-align:center;">' +
420   - '<div class="checkbox"><input id="group-check-{{::title}}" type="checkbox" ng-click="$table.toggleGroupSelection(group)" ng-checked="group.$selected"/><label for="group-check-{{::title}}"></label></div>' +
421   - '</td>' +
422   - '<td colspan="1000"><b><u>{{ title }}</u></b></td>' +
423   - '</tr>' +
424   - '<tr ng-repeat="$row in group track by $row.Id">' +
425   - '<td ng-if="::$table.selectionColumn" style="width:40px;text-align:center;">' +
426   - '<div class="checkbox"><input id="table-check-{{::title}}{{::$index}}" type="checkbox" ng-click="$table.toggleRowSelection(group, $row)" ng-checked="$row.$selected"/><label for="table-check-{{::title}}{{::$index}}"></label></div>' +
427   - '</td>' +
428   - '<td ng-repeat="$column in $columns | filter: { visible: true } track by $column.key">' +
429   - '{{$column.accessor($row)}}' +
430   - '</td>' +
431   - '<td ng-if="::$table.actionColumn" style="text-align:center;" bind-html-compile="$table.actionColumn.html">' +
432   - '</td>' +
433   - '</tr>' +
434   - '</tbody>';
435   - return tmp;
436   - },
437   - compile: function (element, attrs) {
438   - var selectionElement = _findSelectionColumn(element);
439   - var actionsElement = _findActionColumn(element);
440   -
441   - return link;
442   -
443   - function link(scope, element, attrs) {
444   - scope.$table.actionColumn = actionsElement;
445   - scope.$table.selectionColumn = selectionElement;
446   - scope.$table.getCellValue = getCellValue;
447   -
448   - function getCellValue(row, col) {
449   - console.log('GetCellValue is depreciated for performance, please use "$column.accessor($row)" instead, functions are now precompilied;');
450   - if (typeof col.binding === 'string')
451   - return $parse(col.binding)(row);
452   - else if (angular.isFunction(col.binding))
453   - return col.binding(row, col);
454   - else
455   - return '';
456   - }
457   - }
458   - }
459   - }
460   -
461   - function _findActionColumn(element) {
462   - var actionsElement = jQuery(element.context).find('table-actions');
463   - if (actionsElement.length) {
464   - return {
465   - html: actionsElement.html()
466   - };
467   - }
468   - return false;
469   - }
470   -
471   - function _findSelectionColumn(element) {
472   - var selectionElement = jQuery(element.context).find('table-selection');
473   - if (selectionElement.length) {
474   - return {
475   - html: selectionElement.html()
476   - };
477   - }
478   - return false;
479   - }
480   - }
481   -
482   - function tableFooterDirective() {
483   - return {
484   - restrict: 'E',
485   - scope: true,
486   - replace: true,
487   - template: function (element, attrs) {
488   - var template = '' +
489   - '<tfoot><tr><th colspan="100" class="table-arrange">';
490   - if (attrs.title) {
491   - template += '<h3 class="table-title">' + attrs.title + '</h3>';
492   - }
493   - if (attrs.showCount) {
494   - template += '<b class="brand-primary">(showing {{$paging.maxPerPage}} from {{ $paging.totalItems }})</b>';
495   - }
496   - if (attrs.columnsOptions) {
497   - template += '<div class="columns-options">' +
498   - '<a href="" ng-click="$table.reset()"><i class="icon-Reset"></i>Reset</a>' +
499   - '<a href="" ng-click="$table.configureColumns()"><i class="icon-Receipt-2"></i>Arrange</a>' +
500   - '</div>';
501   - }
502   - template += '<div class="pull-right">' +
503   - '<pagination class="pagination-sm" style="margin: 0;" total-items="$paging.totalItems" ng-model="$paging.currentPage" items-per-page="$paging.maxPerPage" boundary-links="true" max-size="5"></pagination>' +
504   - '</div>';
505   - if (attrs.search) {
506   - template += '<input type="text" class="form-control pull-right" style="width:300px" placeholder="Search.." ng-model="$filtering.$" />';
507   - }
508   - template += '</th></tr></tfoot>'
509   - return template;
510   - }
511   - }
512   - }
513   -
514   - softFilter.$inject = ['$filter'];
515   - function softFilter($filter) {
516   - return function (array, filteringConfig) {
517   - var filterFn = $filter('filter');
518   - var filtered = filterFn(array, filteringConfig);
519   - for (var i = 0; i < array.length; i++) {
520   - var target = array[i];
521   - if (filtered.indexOf(target) > -1) {
522   - target.$filtered = true;
523   - } else {
524   - target.$filtered = false;
525   - }
526   - }
527   - return array;
528   - }
529   - }
530   -
531   - function pageGroupFilter() {
532   - return function (groups, pagingConfig) {
533   - var newGroups = {};
534   - var skip = (pagingConfig.currentPage - 1) * pagingConfig.maxPerPage;
535   - var take = pagingConfig.maxPerPage;
536   -
537   - if (angular.isArray(groups)) {
538   - newGroups.undefined = groups.slice(skip, skip + take);
539   - } else {
540   - var groupNames = [];
541   - for (var key in groups) {
542   - if (groups.hasOwnProperty(key) && key[0] != '$') {
543   - groupNames.push(key);
544   - }
545   - }
546   - groupNames.sort();
547   -
548   - angular.forEach(groupNames, function (title) {
549   - var values = groups[title];
550   - if (take <= 0) {
551   - return;
552   - } else if (skip > values.length) {
553   - skip -= values.length;
554   - return;
555   - } else if (skip > 0) {
556   - values.splice(0, skip);
557   - skip = 0;
558   - }
559   -
560   - if (take >= values.length) {
561   - newGroups[title] = values;
562   - take -= values.length;
563   - } else {
564   - newGroups[title] = values.slice(0, take);
565   - take = 0;
566   - }
567   - });
568   - }
569   - return newGroups;
570   - };
571   - }
572   -
573   - function pagingFilter() {
574   - return function (array, pagingConfig) {
575   - if (array.length > pagingConfig.minimum) {
576   -
577   - } else {
578   - return array;
579   - }
580   - }
581   - }
582   -
583   - function publishFilter() {
584   - return function (array, target) {
585   - if (angular.isArray(target)) {
586   - target.length = 0;
587   - [].push.apply(target, array);
588   - }
589   - return array;
590   - }
591   - }
592   -})(angular);
593 0 \ No newline at end of file
common_components/filters/utility.filter.js
... ... @@ -1,110 +0,0 @@
1   -(function(angular){
2   - var module = angular.module('framework.filters.utility',[]);
3   -
4   - module.filter('RemoveSpaces', removeSpaces);
5   - module.filter('Truncate', truncate);
6   - module.filter('AbbrValue', abbrValue);
7   - module.filter('Countdown', countdown);
8   -
9   -
10   - function removeSpaces() {
11   - return function (text) {
12   - return text.replace(/\s/g, '');
13   - }
14   - }
15   -
16   - function truncate () {
17   - return function (text, length, end) {
18   - if (isNaN(length))
19   - length = 10;
20   - if (end === undefined)
21   - end = "...";
22   - if (text.length <= length || text.length - end.length <= length)
23   - { return text; }
24   - else
25   - { return String(text).substring(0, length - end.length) + end; }
26   - }
27   - }
28   -
29   - function abbrValue() {
30   - return function (val) {
31   -
32   - return Math.abs(Number(val)) >= 1.0e+9
33   -
34   - ? Math.round(Math.abs((Number(val)) / 1.0e+9)*10)/10 + "b"
35   - // Six Zeroes for Millions
36   - : Math.abs(Number(val)) >= 1.0e+6
37   -
38   - ? Math.round(Math.abs((Number(val)) / 1.0e+6)*10)/10 + "m"
39   - // Three Zeroes for Thousands
40   - : Math.abs(Number(val)) >= 1.0e+3
41   -
42   - ? Math.round(Math.abs((Number(val)) / 1.0e+3)*10)/10 + "k"
43   -
44   - : Math.abs(Number(val));
45   - }
46   - }
47   -
48   - function countdown() {
49   - return function (input) {
50   - var substitute = function (stringOrFunction, number, strings) {
51   - var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, dateDifference) : stringOrFunction;
52   - var value = (strings.numbers && strings.numbers[number]) || number;
53   - return string.replace(/%d/i, value);
54   - },
55   - nowTime = (new Date()).getTime(),
56   - date = (new Date(input)).getTime(),
57   - allowFuture = true,
58   - strings = {
59   - prefixAgo: null,
60   - prefixFromNow: null,
61   - suffixAgo: "ago",
62   - suffixFromNow: "",//"from now"
63   - seconds: "less than a minute",
64   - minute: "a minute",
65