From 4265eb9689f7e1c358698a44919c4c679e48851d Mon Sep 17 00:00:00 2001 From: Stephan Fortelny Date: Thu, 12 Apr 2018 16:01:02 +0200 Subject: [PATCH 001/121] WIP Cleaning up resource view, list, etc.: Removing deprecated code (tabs, resource generators + factories, restructuring, etc.) --- .../resource-list.directive.html | 56 ++++++++++--------- .../resource-list/resource-list.directive.js | 4 +- .../resource-view.directive.html | 7 ++- .../resource-view/resource-view.directive.js | 7 ++- .../resource/resource-view/subview.factory.js | 16 +++++- app/views/inventory/inventory.controller.html | 2 +- 6 files changed, 55 insertions(+), 37 deletions(-) diff --git a/app/common/components/resource/resource-list/resource-list.directive.html b/app/common/components/resource/resource-list/resource-list.directive.html index bf595f95..d8b7f5be 100644 --- a/app/common/components/resource/resource-list/resource-list.directive.html +++ b/app/common/components/resource/resource-list/resource-list.directive.html @@ -7,26 +7,12 @@ > - -
-
-
-
-
-
+
- - - + + +
-
diff --git a/app/common/components/resource/resource-list/resource-list.directive.js b/app/common/components/resource/resource-list/resource-list.directive.js index 045f84e9..20f51ab0 100644 --- a/app/common/components/resource/resource-list/resource-list.directive.js +++ b/app/common/components/resource/resource-list/resource-list.directive.js @@ -22,7 +22,7 @@ function resourceList (resourceListConfig, ResourceListGetter, ResourceListGette // The parent resource. If it does not have @type, then we are the list of the main inventory view. parentResource: '=?', resourceType: '@', // The type of resource this list is representing. - type: '@' // Type of resource-view this list is in: big, medium, small + type: '@' // Type of resource-view this list is in: big, medium, small TODO Deprecated }, link: { // Note that we load on 'pre' to initialize before our child (or inner) directives so they get real config values @@ -31,7 +31,7 @@ function resourceList (resourceListConfig, ResourceListGetter, ResourceListGette const resourceType = $scope.resourceType $scope.resourceName = utils.Naming.resource(resourceType) if (!resourceType) throw TypeError('resourceList needs a "resourceType" set, not ' + resourceType) - if (!$scope.type) throw TypeError('resourceLists needs a "type" to be "big"|"medium"|"small", not ' + $scope.type) + if (!$scope.type) throw TypeError('resourceLists needs a "type" to be "big"|"medium"|"small", not ' + $scope.type) // TODO Deprecated progressBar.start() // resourceListGetter.getResources will call this too, but doing it here we avoid delay const config = _.cloneDeep(resourceListConfig.views[resourceType]) if (_.isUndefined(config)) throw ReferenceError(resourceType + ' has no config.') diff --git a/app/common/components/resource/resource-view/resource-view.directive.html b/app/common/components/resource/resource-view/resource-view.directive.html index 6fbc075b..7f7b68c5 100644 --- a/app/common/components/resource/resource-view/resource-view.directive.html +++ b/app/common/components/resource/resource-view/resource-view.directive.html @@ -1,5 +1,6 @@ -
-
+
+

Deprecated

+
 
diff --git a/app/common/components/resource/resource-view/resource-view.directive.js b/app/common/components/resource/resource-view/resource-view.directive.js index d0952dbb..ae326ceb 100644 --- a/app/common/components/resource/resource-view/resource-view.directive.js +++ b/app/common/components/resource/resource-view/resource-view.directive.js @@ -1,10 +1,11 @@ +// TODO Deprecated function resourceView (RecursionHelper, Subview, cerberusToView, RESOURCE_CONFIG, ResourceBreadcrumb, ResourceSettings, $compile) { const utils = require('./../../utils') const BIG = 'big' const MED = 'medium' const SM = 'small' - const TYPES = [BIG, MED, SM] + const TYPES = [BIG, MED, SM] // What are types? /** * * Represents a resource. Selects the appropriate view to show the resource, depending of its type. @@ -68,6 +69,7 @@ function resourceView (RecursionHelper, Subview, cerberusToView, RESOURCE_CONFIG iElement.find('#resource-view-body').html(tabs) // If small we use the resourceName + /* DEPRECATED if ($scope.type === BIG) { const subviewsConfig = resourceType ? Subview.getSetting(resourceType, 'subviews') @@ -77,7 +79,7 @@ function resourceView (RecursionHelper, Subview, cerberusToView, RESOURCE_CONFIG 'url', 'date', 'datetime-local', 'search']) // We want to e.has to be fast /** * Sets the subviews tabs by pressing a number from the keyboard. - */ + * const keyPress = e => { if (!AVOID_INPUTS.has(e.target.type) && _.inRange(e.which, 49, 49 + num)) { // 49 is the keyCode for '1' $scope.$evalAsync(() => { $scope.tabs.active = e.which - 49 }) @@ -86,6 +88,7 @@ function resourceView (RecursionHelper, Subview, cerberusToView, RESOURCE_CONFIG $(document).keypress(keyPress) $scope.$on('$destroy', () => $(document).off('keypress', null, keyPress)) } + */ } } diff --git a/app/common/components/resource/resource-view/subview.factory.js b/app/common/components/resource/resource-view/subview.factory.js index ba66b61a..00207bf3 100644 --- a/app/common/components/resource/resource-view/subview.factory.js +++ b/app/common/components/resource/resource-view/subview.factory.js @@ -20,7 +20,18 @@ function SubviewFactory (ResourceViewGenerator, RESOURCE_CONFIG) { return this.compile(subviewsConfig, $scope) } - static _template (subviewsConfig, $scope) { + static _template () { + return ` + + + ` + /* let body = `` _.forEach(subviewsConfig, (option) => { let uid = option.view + option.resourceType @@ -35,12 +46,13 @@ function SubviewFactory (ResourceViewGenerator, RESOURCE_CONFIG) { ${option.name}
-
${this.view(option)}
+
` }) return body + '
' + */ } static view (option) { diff --git a/app/views/inventory/inventory.controller.html b/app/views/inventory/inventory.controller.html index 9f23b6a2..8921558c 100644 --- a/app/views/inventory/inventory.controller.html +++ b/app/views/inventory/inventory.controller.html @@ -5,7 +5,7 @@ - +
From 7e52f09f891250b42011d586a8a62ac98b062b0c Mon Sep 17 00:00:00 2001 From: Stephan Fortelny Date: Fri, 13 Apr 2018 12:28:29 +0200 Subject: [PATCH 002/121] WIP Cleaning up resource view, list, etc. --- app/common/components/resource/index.js | 1 - .../resource-list-config.factory.js | 536 +++++++++--------- .../resource-list-getter-big.factory.js | 1 + .../resource-list-getter.factory.js | 184 +++++- .../resource-list-selector.factory.js | 16 +- .../resource-list.directive.html | 16 +- .../resource-list/resource-list.directive.js | 44 +- .../resource-view.directive.html | 32 +- .../resource-view/resource-view.directive.js | 84 +-- .../resource/resource-view/subview.factory.js | 76 --- app/views/inventory/inventory.controller.js | 1 + 11 files changed, 484 insertions(+), 507 deletions(-) delete mode 100644 app/common/components/resource/resource-view/subview.factory.js diff --git a/app/common/components/resource/index.js b/app/common/components/resource/index.js index 0b3f7747..5d701c19 100644 --- a/app/common/components/resource/index.js +++ b/app/common/components/resource/index.js @@ -38,7 +38,6 @@ module.exports = angular.module('common.components.resource', .directive('resourceIcon', require('./resource-icon/resource-icon.directive')) .directive('resourceView', require('./resource-view/resource-view.directive')) .factory('ResourceViewGenerator', require('./resource-view/resource-view-generator.factory')) - .factory('Subview', require('./resource-view/subview.factory')) .directive('resourceButton', require('./resource-button/resource-button.directive')) .directive('deleteButton', require('./delete-button/delete-button.directive')) .directive('resource', require('./resource/resource.directive')) diff --git a/app/common/components/resource/resource-list/resource-list-config.factory.js b/app/common/components/resource/resource-list/resource-list-config.factory.js index 68a47546..5066c378 100644 --- a/app/common/components/resource/resource-list/resource-list-config.factory.js +++ b/app/common/components/resource/resource-list/resource-list-config.factory.js @@ -153,13 +153,14 @@ function resourceListConfig (RESOURCE_SEARCH, ResourceSettings, CONSTANTS, schem } } - function hasGroupCallback (resourceName) { + /* function hasGroupCallback (resourceName) { const resourceType = Naming.type(resourceName) return (where, ancestors) => { const parents = _(ancestors).filter({'@type': resourceType}).flatMapDeep('_id').value() where['_id'] = {'$in': _(ancestors).flatMapDeep(resourceName).concat(parents).uniq().value()} } } + */ // We use the typeahead to retrieve us the ancestors of the device :-) // todo ^ makes to show [object Object] in the typeahead field @@ -186,285 +187,268 @@ function resourceListConfig (RESOURCE_SEARCH, ResourceSettings, CONSTANTS, schem } return { - views: { - default: { // This is not used, but provided as a template - search: { - params: RESOURCE_SEARCH.params, - defaultParams: {'@type': 'Computer'}, - // subview (parent-resource is set) + search: { + params: RESOURCE_SEARCH.params.concat([ + {key: 'label', name: 'Label', placeholder: 'Label...', realKey: 'labelId'}, + { + key: '@type', + name: 'Type of device', + select: 'Device', + comparison: '=', + description: 'The type of the device: Computer, Mobile, Computer monitor...' }, - buttons: { - templateUrl: '' + { + key: 'pid', + name: 'Pid', + placeholder: 'The Platform Identifier...' }, - table: { - // th and td need to share the same order - th: [{key: '', name: ''}], - td: [{value: ''}, {templateUrl: ''}] - } - }, - Device: { - search: { - params: RESOURCE_SEARCH.params.concat([ - {key: 'label', name: 'Label', placeholder: 'Label...', realKey: 'labelId'}, - { - key: '@type', - name: 'Type of device', - select: 'Device', - comparison: '=', - description: 'The type of the device: Computer, Mobile, Computer monitor...' - }, - { - key: 'pid', - name: 'Pid', - placeholder: 'The Platform Identifier...' - }, - { - key: 'gid', - name: 'Gid', - placeholder: 'The Giver Identifier...' - }, - { - key: 'rid', - name: 'Rid', - placeholder: 'The Refurbisher Identifier...' - }, - { - key: 'type', - name: 'Subtype of device', - select: _(schema.schema) // We get all subtypes of devices - .filter((r, n) => _.isObject(r) && 'type' in r && _.includes(deviceSettings.types, Naming.type(n))) - .flatMap(r => r['type']['allowed']) - .uniq() - .value(), - comparison: '=', - description: 'Subtypes of devices...' - }, - {key: 'serialNumber', name: 'Serial Number', placeholder: 'S/N...'}, - {key: 'model', name: 'Model', placeholder: 'Vaio...'}, - {key: 'manufacturer', name: 'Manufacturer', placeholder: 'Apple...'}, - {key: 'parent', name: 'Components of', placeholder: 'Identifier of the computer'}, - // { key: 'totalMemory', name: 'Total of RAM', placeholder: 'In Gigabytes...'}, - // { key: 'event', name: 'Type of event', placeholder: 'Devices with this event...'}, todo - // { key: 'byUser', name: 'Author', placeholder: 'email or name of the author...'}, // todo - // { key: '_created', name: 'Registered in', placeholder: 'YYYY-MM-DD' }, - // { key: '_updated', name: 'Last updated in', placeholder: 'YYYY-MM-DD'}, - { - key: 'public', - name: 'Is public', - select: ['Yes', 'No'], - boolean: true, - comparison: '=', - description: 'Match devices that have a public link.' - }, - { - key: 'event', - name: 'Has event of type', - select: 'devices:DeviceEvent', - comparison: '=', - realKey: 'events.@type', - description: 'Match only devices that have a specific type of event.' - }, - { - key: 'event_id', - name: 'Has event', - realKey: 'events._id', - placeholder: 'ID of event', - comparison: '=', - description: 'Match only devices that have a specific event.' - }, - LAST_EVENT, - { - key: 'eventIncidence', - name: 'Has an incidence', - realKey: 'events.incidence', - select: ['Yes', 'No'], - boolean: true, - comparison: '=' - }, - { - key: 'eventUpdatedBefore', - name: 'Event performed before or eq', - date: true, - comparison: '<=', - placeholder: h.datePlaceholder, - realKey: 'events._updated' - }, - { - key: 'eventUpdatedAfter', - name: 'Event performed after or eq', - date: true, - comparison: '>=', - placeholder: h.datePlaceholder, - realKey: 'events._updated' - }, - { - key: 'erase', - name: 'Erasure has', - realKey: 'events.success', // todo this works because success field is only for erasures - select: ['Succeed', 'Failed'], - boolean: true, - comparison: '=', - description: 'Computers or their hard-drives that have such erasures.' - }, - { - key: 'receiver', - name: 'Receiver', - typeahead: ACCOUNT_TYPEAHEAD, - realKey: 'events.receiver', - comparison: '=', - placeholder: 'Type an e-mail', - description: 'Match devices that were given to a specific user.' - }, - { - key: 'to', - name: 'Assigned to', - typeahead: ACCOUNT_TYPEAHEAD, - realKey: 'events.to', - comparison: '=', - placeholder: 'Type an e-mail', - description: 'Match devices that were assigned to a specific user.' - }, - { - key: 'from', - name: 'Deassigned from', - typeahead: ACCOUNT_TYPEAHEAD, - placeholder: 'Type an e-mail', - realKey: 'events.to', - comparison: '=', - description: 'Match devices that were de-assigned from a specific user.' - }, - { - key: 'own', - name: 'Owns', - typeahead: ACCOUNT_TYPEAHEAD, - realKey: 'owners', - comparison: 'in', - placeholder: 'Type an e-mail', - description: 'Match devices that are actually assigned to a specific user.' - }, - { - key: 'not-own', - name: 'Does not own', - typeahead: ACCOUNT_TYPEAHEAD, - realKey: 'owners', - comparison: 'nin', - placeholder: 'Type an e-mail', - description: 'Match devices that are actually not assigned to a specific user.' - }, - INSIDE_LOT, - OUTSIDE_LOT, - INSIDE_PACKAGE, - INSIDE_PLACE, - INSIDE_PALLET, - GROUP_INCLUSION, - OUTSIDE_GROUP, - { - key: 'snapshot-software', - name: 'Has a Snapshot made with', - realKey: 'events.snapshotSoftware', - select: SNAPSHOT_SOFTWARE_ALLOWED, - comparison: '=', - description: 'The device has a Snapshot made with a specific software.' - }, - { - key: 'not-snapshot-software', - name: 'Has not a Snapshot made with', - realKey: 'events.snapshotSoftware', - select: SNAPSHOT_SOFTWARE_ALLOWED, - comparison: '!=', - description: 'The device has not a Snapshot made with a specific software.' - }, - { - key: 'event-label', - realKey: 'events.label', - name: 'Label of the event', - placeholder: 'Start writing the label...', - description: 'The name the user wrote in the event.' - }, - { - key: 'placeholder', - name: 'Is Placeholder', - select: ['Yes', 'No'], - boolean: true, - comparison: '=', - description: 'Match devices that are placeholders.' - }, - { - key: 'not-event', - name: 'Has not event', - select: 'devices:DeviceEvent', - comparison: '!=', - realKey: 'events.@type', - description: 'Match only devices that have not a specific type of event. Example: devices not ready.' - }, - { - key: 'is-component', - name: 'Is component', - realKey: '@type', - select: ['Yes', 'No'], - boolean: true, - comparison: (value, RSettings) => ({[value ? '$in' : '$nin']: RSettings('Component').subResourcesNames}), - description: 'Match devices depending if they are components or not.' - }, - { - key: 'active', - name: 'Active', - realKey: 'dh$active', - select: ['Yes', 'No'], - boolean: true, - comparison: '=', - description: 'Match devices that are not recycled, disposed, a final user received, or moved to another inventory.' - }, - { - key: 'rangeIsAtLeast', - name: 'Range is at least', - realKey: 'condition.general.range', - select: conditionRange, - comparison: value => ({$nin: _.takeWhile(conditionRange, v => v !== value), $ne: null}), - description: 'Match devices that are of range or above.' - }, - { - key: 'rangeIs', - name: 'Range is', - realKey: 'condition.general.range', - select: conditionRange, - comparison: '=', - description: 'Match devices that are of range.' - }, - { - key: 'rangeIsAtMost', - name: 'Range is at most', - realKey: 'condition.general.range', - select: conditionRange, - comparison: value => ({'$nin': _.takeRightWhile(conditionRange, v => v !== value)}), - description: 'Match devices that are of range or below.' - }, - { - key: 'pricing.total.standard', - name: 'Price is at most', - comparison: '<=', - number: true - }, - { - key: 'pricing.total.standard', - name: 'Price is at least', - comparison: '>=', - number: true - } - ]), - defaultParams: {'is-component': 'No', 'active': 'Yes'}, - subResource: { - Event: {key: 'device', field: '_id'} - } + { + key: 'gid', + name: 'Gid', + placeholder: 'The Giver Identifier...' }, - buttons: { - templateUrl: configFolder + '/resource-list-config-device' + { + key: 'rid', + name: 'Rid', + placeholder: 'The Refurbisher Identifier...' }, - table: { - th: [f.id.th, f['@type'].th, f.type.th, f.model.th, f.price.th, f.range.th, f.lastEvent.thDef, f.created.th], - td: [f.id.td, f['@type'].td, f.type.td, f.model.td, f.price.td, f.range.td, f.lastEvent.td, f.created.td] + { + key: 'type', + name: 'Subtype of device', + select: _(schema.schema) // We get all subtypes of devices + .filter((r, n) => _.isObject(r) && 'type' in r && _.includes(deviceSettings.types, Naming.type(n))) + .flatMap(r => r['type']['allowed']) + .uniq() + .value(), + comparison: '=', + description: 'Subtypes of devices...' + }, + {key: 'serialNumber', name: 'Serial Number', placeholder: 'S/N...'}, + {key: 'model', name: 'Model', placeholder: 'Vaio...'}, + {key: 'manufacturer', name: 'Manufacturer', placeholder: 'Apple...'}, + {key: 'parent', name: 'Components of', placeholder: 'Identifier of the computer'}, + // { key: 'totalMemory', name: 'Total of RAM', placeholder: 'In Gigabytes...'}, + // { key: 'event', name: 'Type of event', placeholder: 'Devices with this event...'}, todo + // { key: 'byUser', name: 'Author', placeholder: 'email or name of the author...'}, // todo + // { key: '_created', name: 'Registered in', placeholder: 'YYYY-MM-DD' }, + // { key: '_updated', name: 'Last updated in', placeholder: 'YYYY-MM-DD'}, + { + key: 'public', + name: 'Is public', + select: ['Yes', 'No'], + boolean: true, + comparison: '=', + description: 'Match devices that have a public link.' + }, + { + key: 'event', + name: 'Has event of type', + select: 'devices:DeviceEvent', + comparison: '=', + realKey: 'events.@type', + description: 'Match only devices that have a specific type of event.' + }, + { + key: 'event_id', + name: 'Has event', + realKey: 'events._id', + placeholder: 'ID of event', + comparison: '=', + description: 'Match only devices that have a specific event.' + }, + LAST_EVENT, + { + key: 'eventIncidence', + name: 'Has an incidence', + realKey: 'events.incidence', + select: ['Yes', 'No'], + boolean: true, + comparison: '=' + }, + { + key: 'eventUpdatedBefore', + name: 'Event performed before or eq', + date: true, + comparison: '<=', + placeholder: h.datePlaceholder, + realKey: 'events._updated' + }, + { + key: 'eventUpdatedAfter', + name: 'Event performed after or eq', + date: true, + comparison: '>=', + placeholder: h.datePlaceholder, + realKey: 'events._updated' + }, + { + key: 'erase', + name: 'Erasure has', + realKey: 'events.success', // todo this works because success field is only for erasures + select: ['Succeed', 'Failed'], + boolean: true, + comparison: '=', + description: 'Computers or their hard-drives that have such erasures.' + }, + { + key: 'receiver', + name: 'Receiver', + typeahead: ACCOUNT_TYPEAHEAD, + realKey: 'events.receiver', + comparison: '=', + placeholder: 'Type an e-mail', + description: 'Match devices that were given to a specific user.' + }, + { + key: 'to', + name: 'Assigned to', + typeahead: ACCOUNT_TYPEAHEAD, + realKey: 'events.to', + comparison: '=', + placeholder: 'Type an e-mail', + description: 'Match devices that were assigned to a specific user.' + }, + { + key: 'from', + name: 'Deassigned from', + typeahead: ACCOUNT_TYPEAHEAD, + placeholder: 'Type an e-mail', + realKey: 'events.to', + comparison: '=', + description: 'Match devices that were de-assigned from a specific user.' + }, + { + key: 'own', + name: 'Owns', + typeahead: ACCOUNT_TYPEAHEAD, + realKey: 'owners', + comparison: 'in', + placeholder: 'Type an e-mail', + description: 'Match devices that are actually assigned to a specific user.' + }, + { + key: 'not-own', + name: 'Does not own', + typeahead: ACCOUNT_TYPEAHEAD, + realKey: 'owners', + comparison: 'nin', + placeholder: 'Type an e-mail', + description: 'Match devices that are actually not assigned to a specific user.' + }, + INSIDE_LOT, + OUTSIDE_LOT, + INSIDE_PACKAGE, + INSIDE_PLACE, + INSIDE_PALLET, + GROUP_INCLUSION, + OUTSIDE_GROUP, + { + key: 'snapshot-software', + name: 'Has a Snapshot made with', + realKey: 'events.snapshotSoftware', + select: SNAPSHOT_SOFTWARE_ALLOWED, + comparison: '=', + description: 'The device has a Snapshot made with a specific software.' + }, + { + key: 'not-snapshot-software', + name: 'Has not a Snapshot made with', + realKey: 'events.snapshotSoftware', + select: SNAPSHOT_SOFTWARE_ALLOWED, + comparison: '!=', + description: 'The device has not a Snapshot made with a specific software.' + }, + { + key: 'event-label', + realKey: 'events.label', + name: 'Label of the event', + placeholder: 'Start writing the label...', + description: 'The name the user wrote in the event.' + }, + { + key: 'placeholder', + name: 'Is Placeholder', + select: ['Yes', 'No'], + boolean: true, + comparison: '=', + description: 'Match devices that are placeholders.' + }, + { + key: 'not-event', + name: 'Has not event', + select: 'devices:DeviceEvent', + comparison: '!=', + realKey: 'events.@type', + description: 'Match only devices that have not a specific type of event. Example: devices not ready.' + }, + { + key: 'is-component', + name: 'Is component', + realKey: '@type', + select: ['Yes', 'No'], + boolean: true, + comparison: (value, RSettings) => ({[value ? '$in' : '$nin']: RSettings('Component').subResourcesNames}), + description: 'Match devices depending if they are components or not.' + }, + { + key: 'active', + name: 'Active', + realKey: 'dh$active', + select: ['Yes', 'No'], + boolean: true, + comparison: '=', + description: 'Match devices that are not recycled, disposed, a final user received, or moved to another inventory.' + }, + { + key: 'rangeIsAtLeast', + name: 'Range is at least', + realKey: 'condition.general.range', + select: conditionRange, + comparison: value => ({$nin: _.takeWhile(conditionRange, v => v !== value), $ne: null}), + description: 'Match devices that are of range or above.' + }, + { + key: 'rangeIs', + name: 'Range is', + realKey: 'condition.general.range', + select: conditionRange, + comparison: '=', + description: 'Match devices that are of range.' + }, + { + key: 'rangeIsAtMost', + name: 'Range is at most', + realKey: 'condition.general.range', + select: conditionRange, + comparison: value => ({'$nin': _.takeRightWhile(conditionRange, v => v !== value)}), + description: 'Match devices that are of range or below.' + }, + { + key: 'pricing.total.standard', + name: 'Price is at most', + comparison: '<=', + number: true + }, + { + key: 'pricing.total.standard', + name: 'Price is at least', + comparison: '>=', + number: true } - }, + ]), + defaultParams: {'is-component': 'No', 'active': 'Yes'}, + subResource: { + Event: {key: 'device', field: '_id'} + } + }, + buttons: { + templateUrl: configFolder + '/resource-list-config-device' + }, + table: { + th: [f.id.th, f['@type'].th, f.type.th, f.model.th, f.price.th, f.range.th, f.lastEvent.thDef, f.created.th], + td: [f.id.td, f['@type'].td, f.type.td, f.model.td, f.price.td, f.range.td, f.lastEvent.td, f.created.td] + } + /* Lot: { search: { params: RESOURCE_SEARCH.params.concat([ @@ -689,7 +673,7 @@ function resourceListConfig (RESOURCE_SEARCH, ResourceSettings, CONSTANTS, schem td: [f.email.td, f.name.td, f.organization.td, f.updated.td] } } - } + */ } } diff --git a/app/common/components/resource/resource-list/resource-list-getter-big.factory.js b/app/common/components/resource/resource-list/resource-list-getter-big.factory.js index b95a0c38..3ba83c94 100644 --- a/app/common/components/resource/resource-list/resource-list-getter-big.factory.js +++ b/app/common/components/resource/resource-list/resource-list-getter-big.factory.js @@ -2,6 +2,7 @@ * @param {ResourceListGetter} ResourceListGetter * @returns {ResourceListGetterBig} * @constructor + * TODO Merge to ResourceListGetter */ function ResourceListGetterFactoryBig (ResourceListGetter) { /** diff --git a/app/common/components/resource/resource-list/resource-list-getter.factory.js b/app/common/components/resource/resource-list/resource-list-getter.factory.js index 78039b8e..e89f480d 100644 --- a/app/common/components/resource/resource-list/resource-list-getter.factory.js +++ b/app/common/components/resource/resource-list/resource-list-getter.factory.js @@ -67,7 +67,7 @@ function ResourceListGetterFactory (ResourceSettings) { this._filtersBySource[source] = newFilters // Let's merge the different filters in a single one this._filters = {} - _.merge.call(_, this._filters, ..._.values(this._filtersBySource)) + _.merge(this._filters, ..._.values(this._filtersBySource)) // The 'search' filters have preference over others _.merge(this._filters, this._filtersBySource[SEARCH]) // todo if this is called multiple times for the same parameters use isEqual and firstTime combo @@ -178,9 +178,187 @@ function ResourceListGetterFactory (ResourceSettings) { return this.server.getList(q).then(resources => { if (showProgressBar) this.progressBar.complete() if (!getNextPage) this.resources.length = 0 + // console.log('Resources' + JSON.stringify(resources)) + resources = [ + { + 'label': 'BDR', + '_updated': '2018-04-11T10:11:49', + '_links': { + 'self': { + 'href': 'db1/lots/NCZ0iW0mC', + 'title': 'Lot' + } + }, + 'perms': [], + 'children': {}, + 'byUser': '5ac49232a0961e72684082dc', + '_created': '2018-04-11T10:11:49', + '@type': 'Lot', + '_id': 'NCZ0iW0mC', + 'sharedWith': [], + 'ancestors': [] + }, + { + 'label': 'lot1', + '_updated': '2018-04-04T08:52:46', + '_links': { + 'self': { + 'href': 'db1/lots/PuDTLblX', + 'title': 'Lot' + } + }, + 'perms': [ + { + 'perm': 'r', + 'account': '5ac4925da0961e72684083e8' + } + ], + 'children': { + 'pallets': [ + 'PuDTdt9X' + ] + }, + 'byUser': '5ac49232a0961e72684082dc', + '_created': '2018-04-04T08:52:34', + '@type': 'Lot', + '_id': 'PuDTLblX', + 'sharedWith': [ + '5ac4925da0961e72684083e8' + ], + 'ancestors': [ + { + 'component': [], + 'packages': [], + 'incoming-lot': [], + 'places': [], + 'pallets': [], + 'lots': [], + '_id': 'XuRYHTxP', + 'outgoing-lot': [], + 'devices': [], + '@type': 'Place' + } + ] + }, + { + 'label': 'Lot from User', + '_updated': '2018-04-04T08:52:45', + '_links': { + 'self': { + 'href': 'db1/lots/XOmGHs3i', + 'title': 'Lot' + } + }, + 'perms': [], + 'children': {}, + 'byUser': '5ac49232a0961e72684082dc', + '_created': '2018-04-04T08:52:45', + '@type': 'Lot', + '_id': 'XOmGHs3i', + 'sharedWith': [], + 'ancestors': [] + }, + { + 'placeholder': true, + '_links': { + 'self': { + 'href': 'db1/devices/469', + 'title': 'Device' + } + }, + 'isUidSecured': true, + 'components': [], + '_created': '2018-04-11T16:28:24', + '_id': '469', + 'ancestors': [], + '_updated': '2018-04-11T16:28:24', + 'events': [ + { + '_updated': '2018-04-11T16:28:24', + 'byUser': '5ac49232a0961e72684082dc', + 'secured': false, + 'incidence': false, + '_id': '5ace37a8a0961e0651b59a50', + '@type': 'devices:Register' + } + ], + '@type': 'Device', + 'totalHardDriveSize': 0, + 'forceCreation': false, + '_etag': '5be9ecdf01ab5bfcac23153bec0baece7a68bf99', + 'public': false, + 'perms': [], + 'totalRamSize': 0 + }, + { + 'placeholder': true, + '_links': { + 'self': { + 'href': 'db1/devices/468', + 'title': 'Device' + } + }, + 'isUidSecured': true, + 'components': [], + '_created': '2018-04-11T16:28:24', + '_id': '468', + 'ancestors': [], + '_updated': '2018-04-11T16:28:24', + 'events': [ + { + '_updated': '2018-04-11T16:28:24', + 'byUser': '5ac49232a0961e72684082dc', + 'secured': false, + 'incidence': false, + '_id': '5ace37a8a0961e0651b59a4f', + '@type': 'devices:Register' + } + ], + '@type': 'Device', + 'totalHardDriveSize': 0, + 'forceCreation': false, + '_etag': '5be9ecdf01ab5bfcac23153bec0baece7a68bf99', + 'public': false, + 'perms': [], + 'totalRamSize': 0 + }, + { + 'placeholder': true, + '_links': { + 'self': { + 'href': 'db1/devices/467', + 'title': 'Device' + } + }, + 'isUidSecured': true, + 'components': [], + '_created': '2018-04-11T16:28:24', + '_id': '467', + 'ancestors': [], + '_updated': '2018-04-11T16:28:24', + 'events': [ + { + '_updated': '2018-04-11T16:28:24', + 'byUser': '5ac49232a0961e72684082dc', + 'secured': false, + 'incidence': false, + '_id': '5ace37a8a0961e0651b59a4e', + '@type': 'devices:Register' + } + ], + '@type': 'Device', + 'totalHardDriveSize': 0, + 'forceCreation': false, + '_etag': '5be9ecdf01ab5bfcac23153bec0baece7a68bf99', + 'public': false, + 'perms': [], + 'totalRamSize': 0 + } + ] + _.assign(this.resources, this.resources.concat(resources)) - this.pagination.morePagesAvailable = resources._meta.page * resources._meta.max_results < resources._meta.total - this.pagination.totalPages = resources._meta.total + this.pagination.morePagesAvailable = resources._meta && resources._meta.page * resources._meta.max_results < resources._meta.total + this.pagination.totalPages = resources._meta && resources._meta.total // broadcast to callbacks _.invokeMap(this._callbacksOnGetting, _.call, null, this.resources, this.resourceType, this.pagination, getNextPage) }) diff --git a/app/common/components/resource/resource-list/resource-list-selector.factory.js b/app/common/components/resource/resource-list/resource-list-selector.factory.js index 70f0dfb3..4fc75b08 100644 --- a/app/common/components/resource/resource-list/resource-list-selector.factory.js +++ b/app/common/components/resource/resource-list/resource-list-selector.factory.js @@ -43,21 +43,12 @@ function ResourceSelectorFactory () { * * @param {object} resource - The resource to select/deselect * @param {$event} $event - JQuery's/JQLite event object - * @param {number} $index - The index of the resource in the *resources* list. */ - toggle (resource, $event, $index) { + toggle (resource) { if (this.isInList(resource)) { // Remove this.remove(resource) } else { // Add - if ($event.shiftKey) { // Add multiple - let foundPreviousSelectedOne = false - // Selects all resources until finds a previously selected resources or reaches the beginning - for (let i = $index; i >= 0 && !foundPreviousSelectedOne; i--) { - foundPreviousSelectedOne = !this.add(this.resources[i]) - } - } else { // Add one - this.add(resource) - } + this.add(resource) } } @@ -69,8 +60,7 @@ function ResourceSelectorFactory () { let self = this if (selectAll) { _.forEach(this.resources, resource => { self.add(resource) }) // Note that add can return false - } - else { + } else { this.deselectAll() } } diff --git a/app/common/components/resource/resource-list/resource-list.directive.html b/app/common/components/resource/resource-list/resource-list.directive.html index d8b7f5be..c2ff8105 100644 --- a/app/common/components/resource/resource-list/resource-list.directive.html +++ b/app/common/components/resource/resource-list/resource-list.directive.html @@ -1,4 +1,4 @@ - +
+