-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jkmarx/file browser refactor ctrl (#1785)
* Refactor directives according to angular style guide. * Remove unneccessary variable. * Fix spacing. * Remove unneccessary rootScope variable. * Refactor ctrl. * Reorder inputs. * Update module and setting file to style guide. (#1786) * Update module and setting file to style guide. * Jkmarx/file browser refactor services (#1787) * Refactor main factory file according to style guide. * Update main factory test and remove unneccessary variables. * Update smaller services according to style guide. (#1788) * Update smaller services according to style guide. * Jkmarx/generalize attribute filter (#1790) * Move uiSelectedFields to service. * Add assay filter service. * Move methods to assay-filters-ctrl * Update initialize events. * Add and update unit test for ctrl. * Fix bug related to url query. * Remove broadcast and use watcher. * Remove console. * Update unit test. * Add ctrl comments. * Fix scope and remove unneccessary variable. * fix bug due to url query generation. * Add comments and unit test. * Add unit test and comments.
- Loading branch information
Showing
30 changed files
with
1,860 additions
and
1,433 deletions.
There are no files selected for viewing
139 changes: 76 additions & 63 deletions
139
refinery/ui/source/js/file-browser/ctrls/assay-files-util-modal-ctrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,88 @@ | ||
'use strict'; | ||
(function () { | ||
'use strict'; | ||
|
||
function AssayFilesUtilModalCtrl ( | ||
fileBrowserFactory, | ||
$log, | ||
$q, | ||
$scope, | ||
selectedFilterService, | ||
$uibModalInstance, | ||
$window | ||
) { | ||
var vm = this; | ||
vm.assayAttributeOrder = []; | ||
angular | ||
.module('refineryFileBrowser') | ||
.controller('AssayFilesUtilModalCtrl', AssayFilesUtilModalCtrl); | ||
|
||
// modal close button | ||
vm.close = function () { | ||
$uibModalInstance.close('close'); | ||
}; | ||
AssayFilesUtilModalCtrl.$inject = [ | ||
'$log', | ||
'$q', | ||
'$scope', | ||
'$uibModalInstance', | ||
'$window', | ||
'fileBrowserFactory', | ||
'selectedFilterService' | ||
]; | ||
|
||
// Refresh attribute lists when modal opens | ||
vm.refreshAssayAttributes = function () { | ||
var assayUuid = $window.externalAssayUuid; | ||
fileBrowserFactory.getAssayAttributeOrder(assayUuid).then(function () { | ||
vm.assayAttributeOrder = fileBrowserFactory.assayAttributeOrder; | ||
}, function (error) { | ||
$log.error(error); | ||
}); | ||
}; | ||
function AssayFilesUtilModalCtrl ( | ||
$log, | ||
$q, | ||
$scope, | ||
$uibModalInstance, | ||
$window, | ||
fileBrowserFactory, | ||
selectedFilterService | ||
) { | ||
var vm = this; | ||
vm.assayAttributeOrder = []; | ||
vm.close = close; | ||
vm.isAttributeSelected = isAttributeSelected; | ||
vm.refreshAssayAttributes = refreshAssayAttributes; | ||
vm.updateAssayAttributes = updateAssayAttributes; | ||
vm.updateAttributeRank = updateAttributeRank; | ||
|
||
// Update ranks and attributes for owners | ||
vm.updateAssayAttributes = function (attributeParam) { | ||
fileBrowserFactory.postAssayAttributeOrder(attributeParam).then(function () { | ||
}); | ||
}; | ||
activate(); | ||
/* | ||
* ----------------------------------------------------------------------------- | ||
* Methods | ||
* ----------------------------------------------------------------------------- | ||
*/ | ||
function activate () { | ||
refreshAssayAttributes(); | ||
} | ||
|
||
// update rank of item moved | ||
vm.updateAttributeRank = function (attributeObj, index) { | ||
// when item is moved, it's duplication is removed | ||
vm.assayAttributeOrder.splice(index, 1); | ||
// modal close button | ||
function close () { | ||
$uibModalInstance.close('close'); | ||
} | ||
|
||
for (var i = 0; i < vm.assayAttributeOrder.length; i++) { | ||
// locally update all ranks | ||
vm.assayAttributeOrder[i].rank = i + 1; | ||
if (vm.assayAttributeOrder[i].solr_field === attributeObj.solr_field) { | ||
// post rank update for attribute moved | ||
vm.updateAssayAttributes(vm.assayAttributeOrder[i]); | ||
function isAttributeSelected (internalName) { | ||
if (selectedFilterService.attributeSelectedFields.hasOwnProperty(internalName)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// Refresh attribute lists when modal opens | ||
function refreshAssayAttributes () { | ||
var assayUuid = $window.externalAssayUuid; | ||
fileBrowserFactory.getAssayAttributeOrder(assayUuid).then(function () { | ||
vm.assayAttributeOrder = fileBrowserFactory.assayAttributeOrder; | ||
}, function (error) { | ||
$log.error(error); | ||
}); | ||
} | ||
}; | ||
|
||
vm.isAttributeSelected = function (internalName) { | ||
if (selectedFilterService.attributeSelectedFields.hasOwnProperty(internalName)) { | ||
return true; | ||
// Update ranks and attributes for owners | ||
function updateAssayAttributes (attributeParam) { | ||
fileBrowserFactory.postAssayAttributeOrder(attributeParam).then(function () { | ||
}); | ||
} | ||
return false; | ||
}; | ||
|
||
vm.refreshAssayAttributes(); | ||
} | ||
// update rank of item moved | ||
function updateAttributeRank (attributeObj, index) { | ||
// when item is moved, it's duplication is removed | ||
vm.assayAttributeOrder.splice(index, 1); | ||
|
||
angular | ||
.module('refineryFileBrowser') | ||
.controller( | ||
'AssayFilesUtilModalCtrl', | ||
[ | ||
'fileBrowserFactory', | ||
'$log', | ||
'$q', | ||
'$scope', | ||
'selectedFilterService', | ||
'$uibModalInstance', | ||
'$window', | ||
AssayFilesUtilModalCtrl | ||
] | ||
); | ||
for (var i = 0; i < vm.assayAttributeOrder.length; i++) { | ||
// locally update all ranks | ||
vm.assayAttributeOrder[i].rank = i + 1; | ||
if (vm.assayAttributeOrder[i].solr_field === attributeObj.solr_field) { | ||
// post rank update for attribute moved | ||
vm.updateAssayAttributes(vm.assayAttributeOrder[i]); | ||
} | ||
} | ||
} | ||
} | ||
})(); |
167 changes: 83 additions & 84 deletions
167
refinery/ui/source/js/file-browser/ctrls/assay-files-util-modal-ctrl.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,102 @@ | ||
/** Unit Tests **/ | ||
'use strict'; | ||
(function () { | ||
/** Unit Tests **/ | ||
'use strict'; | ||
|
||
// Global variable for both test and ctrl. | ||
describe('Controller: Assay Files Util Modal Ctrl', function () { | ||
var ctrl; | ||
var scope; | ||
var factory; | ||
|
||
describe('Controller: Assay Files Util Modal Ctrl', function () { | ||
var ctrl; | ||
var scope; | ||
var factory; | ||
beforeEach(module('refineryApp')); | ||
beforeEach(module('refineryFileBrowser')); | ||
beforeEach(inject(function ($controller, $rootScope, fileBrowserFactory) { | ||
scope = $rootScope.$new(); | ||
// Create mock version of dependency | ||
var $uibModalInstance = { close: function () {} }; | ||
ctrl = $controller( | ||
'AssayFilesUtilModalCtrl', | ||
{ | ||
$scope: scope, | ||
$uibModalInstance: $uibModalInstance | ||
}); | ||
factory = fileBrowserFactory; | ||
})); | ||
|
||
beforeEach(module('refineryApp')); | ||
beforeEach(module('refineryFileBrowser')); | ||
beforeEach(inject(function ($rootScope, _$controller_, _fileBrowserFactory_) { | ||
scope = $rootScope.$new(); | ||
// Create mock version of dependency | ||
var $uibModalInstance = { close: function () {} }; | ||
var $controller = _$controller_; | ||
ctrl = $controller( | ||
'AssayFilesUtilModalCtrl', | ||
{ | ||
$scope: scope, | ||
$uibModalInstance: $uibModalInstance | ||
}); | ||
factory = _fileBrowserFactory_; | ||
})); | ||
it('AssayFilesUtilModalCtrl ctrl should exist', function () { | ||
expect(ctrl).toBeDefined(); | ||
}); | ||
|
||
it('AssayFilesUtilModalCtrl ctrl should exist', function () { | ||
expect(ctrl).toBeDefined(); | ||
}); | ||
it('Data & UI displays variables should exist for views', function () { | ||
expect(ctrl.assayAttributeOrder).toEqual([]); | ||
}); | ||
|
||
it('Data & UI displays variables should exist for views', function () { | ||
expect(ctrl.assayAttributeOrder).toEqual([]); | ||
}); | ||
describe('Refresh and Update AssayFilter from Factory', function () { | ||
it('refreshAssayFilter is method', function () { | ||
expect(angular.isFunction(ctrl.refreshAssayAttributes)).toBe(true); | ||
}); | ||
|
||
describe('Refresh and Update AssayFilter from Factory', function () { | ||
it('refreshAssayFilter is method', function () { | ||
expect(angular.isFunction(ctrl.refreshAssayAttributes)).toBe(true); | ||
}); | ||
it('refreshAssayFiles returns promise', function () { | ||
var mockAssayAttributes = false; | ||
spyOn(factory, 'getAssayAttributeOrder').and.callFake(function () { | ||
return { | ||
then: function () { | ||
mockAssayAttributes = true; | ||
} | ||
}; | ||
}); | ||
|
||
it('refreshAssayFiles returns promise', function () { | ||
var mockAssayAttributes = false; | ||
spyOn(factory, 'getAssayAttributeOrder').and.callFake(function () { | ||
return { | ||
then: function () { | ||
mockAssayAttributes = true; | ||
} | ||
}; | ||
ctrl.refreshAssayAttributes(); | ||
expect(mockAssayAttributes).toEqual(true); | ||
}); | ||
|
||
ctrl.refreshAssayAttributes(); | ||
expect(mockAssayAttributes).toEqual(true); | ||
}); | ||
it('updateAssayAttributes is method', function () { | ||
expect(angular.isFunction(ctrl.updateAssayAttributes)).toBe(true); | ||
}); | ||
|
||
it('updateAssayAttributes is method', function () { | ||
expect(angular.isFunction(ctrl.updateAssayAttributes)).toBe(true); | ||
}); | ||
it('updateAssayAttributes returns promise', function () { | ||
var mockPostAssayAttributes = false; | ||
spyOn(factory, 'postAssayAttributeOrder').and.callFake(function () { | ||
return { | ||
then: function () { | ||
mockPostAssayAttributes = true; | ||
} | ||
}; | ||
}); | ||
|
||
it('updateAssayAttributes returns promise', function () { | ||
var mockPostAssayAttributes = false; | ||
spyOn(factory, 'postAssayAttributeOrder').and.callFake(function () { | ||
return { | ||
then: function () { | ||
mockPostAssayAttributes = true; | ||
} | ||
}; | ||
ctrl.updateAssayAttributes(); | ||
expect(mockPostAssayAttributes).toEqual(true); | ||
}); | ||
|
||
ctrl.updateAssayAttributes(); | ||
expect(mockPostAssayAttributes).toEqual(true); | ||
}); | ||
it('updateAttributeRank method', function () { | ||
expect(angular.isFunction(ctrl.updateAttributeRank)).toBe(true); | ||
}); | ||
|
||
it('updateAttributeRank method', function () { | ||
expect(angular.isFunction(ctrl.updateAttributeRank)).toBe(true); | ||
}); | ||
it('updateAttributeRank returns promise', function () { | ||
var mockPostAssayAttributes = false; | ||
|
||
it('updateAttributeRank returns promise', function () { | ||
var mockPostAssayAttributes = false; | ||
// Mock the array after a drag and drop movement | ||
ctrl.assayAttributeOrder = [ | ||
{ solr_field: 'Title', rank: 1 }, | ||
{ solr_field: 'Character', rank: 2 }, | ||
{ solr_field: 'Cell Type', rank: 3 }, | ||
{ solr_field: 'Name', rank: 4 }, | ||
{ solr_field: 'Character', rank: 2 } | ||
]; | ||
spyOn(ctrl, 'updateAssayAttributes').and.callFake(function () { | ||
mockPostAssayAttributes = true; | ||
return mockPostAssayAttributes; | ||
}); | ||
|
||
// Mock the array after a drag and drop movement | ||
ctrl.assayAttributeOrder = [ | ||
{ solr_field: 'Title', rank: 1 }, | ||
{ solr_field: 'Character', rank: 2 }, | ||
{ solr_field: 'Cell Type', rank: 3 }, | ||
{ solr_field: 'Name', rank: 4 }, | ||
{ solr_field: 'Character', rank: 2 } | ||
]; | ||
spyOn(ctrl, 'updateAssayAttributes').and.callFake(function () { | ||
mockPostAssayAttributes = true; | ||
return mockPostAssayAttributes; | ||
ctrl.updateAttributeRank({ solr_field: 'Character', rank: 2 }, 1); | ||
expect(mockPostAssayAttributes).toEqual(true); | ||
// confirm removal of duplication in method | ||
expect(ctrl.assayAttributeOrder.length).toEqual(4); | ||
// check ranks are updated locally | ||
expect(ctrl.assayAttributeOrder[3].rank).toEqual(4); | ||
expect(ctrl.assayAttributeOrder[2].rank).toEqual(3); | ||
expect(ctrl.assayAttributeOrder[1].rank).toEqual(2); | ||
expect(ctrl.assayAttributeOrder[0].rank).toEqual(1); | ||
}); | ||
|
||
ctrl.updateAttributeRank({ solr_field: 'Character', rank: 2 }, 1); | ||
expect(mockPostAssayAttributes).toEqual(true); | ||
// confirm removal of duplication in method | ||
expect(ctrl.assayAttributeOrder.length).toEqual(4); | ||
// check ranks are updated locally | ||
expect(ctrl.assayAttributeOrder[3].rank).toEqual(4); | ||
expect(ctrl.assayAttributeOrder[2].rank).toEqual(3); | ||
expect(ctrl.assayAttributeOrder[1].rank).toEqual(2); | ||
expect(ctrl.assayAttributeOrder[0].rank).toEqual(1); | ||
}); | ||
}); | ||
}); | ||
})(); |
Oops, something went wrong.