-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors dashboard state to a component
In support of the longer term fix brough on by #1372
- Loading branch information
Showing
12 changed files
with
285 additions
and
323 deletions.
There are no files selected for viewing
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
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,7 +1,11 @@ | ||
import { SharedModule } from '../shared/shared.module.js' | ||
import { DashboardComponent } from './dashboard/dashboard.component.js' | ||
import { DashboardComponentFactory } from './dashboard/dashboard.component.service.js' | ||
|
||
export default angular | ||
.module('app.components', [ | ||
SharedModule | ||
]) | ||
.module('app.components', [ | ||
SharedModule | ||
]) | ||
.component('dashboardComponent', DashboardComponent) | ||
.factory('DashboardsState', DashboardComponentFactory) | ||
.name |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import templateUrl from './dashboard.html' | ||
|
||
export const DashboardComponent = { | ||
templateUrl, | ||
controller: ComponentController, | ||
controllerAs: 'vm' | ||
} | ||
|
||
/** @ngInject */ | ||
function ComponentController ($state, CatalogsState, EventNotifications, lodash, Chargeback, RBAC) { | ||
const vm = this | ||
|
||
const retiredTitle = __('Retire Status') | ||
const allRequestTypes = ['pending', 'approved', 'denied'] | ||
|
||
vm.$onInit = function () { | ||
vm.permissions = { | ||
'monthlyCharges': RBAC.has(RBAC.FEATURES.DASHBOARD.VIEW.MONTHLY_CHARGES) | ||
} | ||
|
||
angular.extend(vm, { | ||
requestsFeature: false, | ||
servicesFeature: false, | ||
servicesCount: { | ||
total: 0, | ||
current: 0, | ||
retired: 0, | ||
soon: 0 | ||
}, | ||
requestsCount: { | ||
total: 0 | ||
}, | ||
navigateToRetiringSoonServicesList: navigateToRetiringSoonServicesList, | ||
navigateToRetiredServicesList: navigateToRetiredServicesList, | ||
navigateToCurrentServicesList: navigateToCurrentServicesList | ||
}) | ||
} | ||
|
||
function navigateToRetiredServicesList () { | ||
$state.go('services', { | ||
'filter': [{ | ||
'id': 'retired', | ||
'title': retiredTitle, | ||
'value': {id: true, title: __('Retired')} | ||
}] | ||
}) | ||
} | ||
|
||
function navigateToRetiringSoonServicesList () { | ||
const currentDate = new Date() | ||
const filters = [] | ||
|
||
filters.push({'id': 'retired', 'title': retiredTitle, 'value': {id: false, title: __('Retires between')}}) | ||
filters.push({'id': 'retires_on', 'operator': '>', 'value': {id: currentDate.toISOString(), title: __('Now')}}) | ||
const days30 = currentDate.setDate(currentDate.getDate() + 30) | ||
filters.push({ | ||
'id': 'retires_on', | ||
'operator': '<', | ||
'value': {id: new Date(days30).toISOString(), title: __('30 Days')} | ||
}) | ||
|
||
$state.go('services', {'filter': filters}) | ||
} | ||
|
||
function navigateToCurrentServicesList () { | ||
$state.go('services', { | ||
'filter': [{ | ||
'id': 'retired', | ||
'title': retiredTitle, | ||
'value': {id: false, title: __('Not Retired')} | ||
}] | ||
}) | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
client/app/components/dashboard/dashboard.component.service.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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** @ngInject */ | ||
export function DashboardComponentFactory (CollectionsApi, RBAC) { | ||
|
||
return { | ||
definedServiceIdsServices: resolveServicesWithDefinedServiceIds, | ||
retiredServices: resolveRetiredServices, | ||
expiringServices: resolveExpiringServices, | ||
allRequests: resolveAllRequests | ||
} | ||
|
||
function pendingRequestsForServiceTemplateProvisionRequest () { | ||
var filterValues = ['approval_state=pending_approval'] | ||
var options = {hide: 'resources', filter: filterValues} | ||
|
||
return CollectionsApi.query('requests', options) | ||
} | ||
|
||
function pendingRequestsForServiceReconfigureRequest () { | ||
var filterValues = ['type=ServiceReconfigureRequest', 'approval_state=pending_approval'] | ||
var options = {hide: 'resources', filter: filterValues} | ||
|
||
return CollectionsApi.query('requests', options) | ||
} | ||
|
||
function approvedRequestsForServiceTemplateProvisionRequest () { | ||
var filterValues = ['type=ServiceTemplateProvisionRequest', 'approval_state=approved'] | ||
var options = {hide: 'resources', filter: filterValues} | ||
|
||
return CollectionsApi.query('requests', options) | ||
} | ||
|
||
function approvedRequestsForServiceReconfigureRequest () { | ||
var filterValues = ['type=ServiceReconfigureRequest', 'approval_state=approved'] | ||
var options = {hide: 'resources', filter: filterValues} | ||
|
||
return CollectionsApi.query('requests', options) | ||
} | ||
|
||
function deniedRequestsForServiceTemplateProvisionRequest () { | ||
var filterValues = ['type=ServiceTemplateProvisionRequest', 'approval_state=denied'] | ||
var options = {hide: 'resources', filter: filterValues} | ||
|
||
return CollectionsApi.query('requests', options) | ||
} | ||
|
||
function deniedRequestsForServiceReconfigureRequest () { | ||
var filterValues = ['type=ServiceReconfigureRequest', 'approval_state=denied'] | ||
var options = {hide: 'resources', filter: filterValues} | ||
|
||
return CollectionsApi.query('requests', options) | ||
} | ||
|
||
function resolveExpiringServices () { | ||
if (RBAC.has('service_view') && RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) { | ||
const currentDate = new Date() | ||
const date1 = 'retires_on>' + currentDate.toISOString() | ||
const days30 = currentDate.setDate(currentDate.getDate() + 30) | ||
const date2 = 'retires_on<' + new Date(days30).toISOString() | ||
const options = {hide: 'resources', filter: ['retired=false', date1, date2]} | ||
|
||
return CollectionsApi.query('services', options) | ||
} | ||
|
||
return true | ||
} | ||
|
||
function resolveRetiredServices () { | ||
if (RBAC.has('service_view') && RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) { | ||
const options = {hide: 'resources', filter: ['service_id=nil', 'retired=true']} | ||
|
||
return CollectionsApi.query('services', options) | ||
} | ||
return true | ||
} | ||
|
||
function resolveServicesWithDefinedServiceIds () { | ||
if (RBAC.has('service_view') && RBAC.has(RBAC.FEATURES.SERVICES.VIEW)) { | ||
const options = { | ||
expand: 'resources', | ||
filter: ['service_id=nil'], | ||
attributes: ['chargeback_report'] | ||
} | ||
|
||
return CollectionsApi.query('services', options) | ||
} | ||
|
||
return true | ||
} | ||
} |
Empty file.
77 changes: 77 additions & 0 deletions
77
client/app/components/dashboard/dashboard.component.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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* global $state, readJSON, RBAC, $httpBackend, $controller, CollectionsApi */ | ||
/* eslint-disable no-unused-expressions */ | ||
describe('State: dashboard', () => { | ||
const permissions = readJSON('tests/mock/rbac/allPermissions.json') | ||
beforeEach(() => { | ||
module('app.core', 'app.states', 'app.orders', 'app.services') | ||
bard.inject('$location', '$rootScope', '$state', '$templateCache', '$httpBackend', '$q', 'RBAC') | ||
RBAC.set(permissions) | ||
}) | ||
|
||
beforeEach(() => { | ||
let d = new Date() | ||
d.setMinutes(d.getMinutes() + 30) | ||
d = d.toISOString() | ||
d = d.substring(0, d.indexOf('.')) | ||
|
||
$httpBackend.whenGET('').respond(200) | ||
}) | ||
|
||
describe('route', () => { | ||
beforeEach(() => { | ||
bard.inject('$location', '$rootScope', '$state', '$templateCache') | ||
}) | ||
|
||
it('should work with $state.go', () => { | ||
$state.go('dashboard') | ||
expect($state.is('dashboard')) | ||
}) | ||
}) | ||
|
||
describe('controller', () => { | ||
let controller, dashboardState | ||
const resolveServicesWithDefinedServiceIds = {} | ||
const retiredServices = {} | ||
const resolveNonRetiredServices = {} | ||
const expiringServices = {} | ||
const resolveAllRequests = [] | ||
|
||
beforeEach(() => { | ||
bard.inject('$controller', '$log', '$state', '$rootScope', 'CollectionsApi', 'RBAC') | ||
|
||
const controllerResolves = { | ||
definedServiceIdsServices: resolveServicesWithDefinedServiceIds, | ||
retiredServices: retiredServices, | ||
nonRetiredServices: resolveNonRetiredServices, | ||
expiringServices: expiringServices, | ||
allRequests: resolveAllRequests | ||
} | ||
dashboardState = $state.get('dashboard') | ||
controller = $controller(dashboardState.controller, controllerResolves) | ||
}) | ||
|
||
it('should be created successfully', () => { | ||
expect(controller).to.be.defined | ||
}) | ||
|
||
describe('resolveExpiringServices', () => { | ||
it('makes a query request using the CollectionApi', () => { | ||
const clock = sinon.useFakeTimers(new Date('2016-01-01').getTime()) | ||
let collectionsApiSpy = sinon.stub(CollectionsApi) | ||
|
||
dashboardState.resolve.expiringServices(collectionsApiSpy, RBAC) | ||
|
||
expect(collectionsApiSpy.query).to.have.been.calledWith('services', { | ||
hide: 'resources', | ||
filter: [ | ||
'retired=false', | ||
'retires_on>2016-01-01T00:00:00.000Z', | ||
'retires_on<2016-01-31T00:00:00.000Z' | ||
] | ||
}) | ||
|
||
clock.restore() | ||
}) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.