Skip to content

Commit

Permalink
Removed unnecessary filtercount functions from explorer views
Browse files Browse the repository at this point in the history
field subquery_count is used as this does not change with the max_results_per_page flag
  • Loading branch information
AllenBW committed Oct 19, 2017
1 parent 58f0c0a commit 13a3614
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 197 deletions.
16 changes: 3 additions & 13 deletions client/app/catalogs/catalog-explorer.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,13 @@ function ComponentController ($state, CatalogsState, ListView, EventNotification
return CatalogsState.getServiceTemplates(limit, offset).then(success, failure)

function success (response) {
vm.serviceTemplateList = response.resources

CatalogsState.getCatalogs(limit, offset).then((response) => {
vm.catalogsList = response.resources
vm.loading = false
vm.toolbarConfig.filterConfig = getFilterConfig()
getFilterCount()
})

function getFilterCount () {
CatalogsState.getMinimal('service_templates').then(success, failure)

function success (result) {
vm.filterCount = result.subcount
vm.toolbarConfig.filterConfig.resultsCount = result.subcount
}
}
vm.serviceTemplateList = response.resources
vm.toolbarConfig.filterConfig = getFilterConfig()
vm.toolbarConfig.filterConfig.resultsCount = response.subquery_count
}

function failure (_error) {
Expand Down
2 changes: 1 addition & 1 deletion client/app/catalogs/catalog-explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ss-card>
</pf-card-view>
</div>
<explorer-pagination count="vm.filterCount"
<explorer-pagination count="vm.toolbarConfig.filterConfig.resultsCount"
limit="vm.limit"
limit-options="vm.limitOptions"
on-update="vm.updatePagination($limit, $offset)">
Expand Down
37 changes: 11 additions & 26 deletions client/app/orders/order-explorer/order-explorer.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const OrderExplorerComponent = {

/** @ngInject */
function ComponentController ($filter, $state, lodash, ListView, Language, OrdersState, ShoppingCart, EventNotifications, Session, RBAC, ModalService,
CollectionsApi, sprintf, Polling, POLLING_INTERVAL) {
CollectionsApi, sprintf, Polling, POLLING_INTERVAL) {
const vm = this
vm.permissions = OrdersState.getPermissions()
vm.$onInit = activate()
Expand Down Expand Up @@ -130,6 +130,7 @@ function ComponentController ($filter, $state, lodash, ListView, Language, Order

return checkApproval() ? menuActions : null
}

function expandRow (item) {
if (!item.disableRowExpansion) {
item.isExpanded = !item.isExpanded
Expand Down Expand Up @@ -204,17 +205,16 @@ function ComponentController ($filter, $state, lodash, ListView, Language, Order
var existingOrders = (angular.isDefined(vm.ordersList) && refresh ? angular.copy(vm.ordersList) : [])

vm.offset = offset
getFilterCount().then(() => {
OrdersState.getOrders(
limit,
offset,
OrdersState.getFilters(),
OrdersState.getSort().currentField,
OrdersState.getSort().isAscending,
refresh).then(querySuccess, queryFailure)
})
OrdersState.getOrders(
limit,
offset,
OrdersState.getFilters(),
OrdersState.getSort().currentField,
OrdersState.getSort().isAscending,
refresh).then(querySuccess, queryFailure)

function querySuccess (response) {
vm.filterCount = response.subquery_count
vm.loading = false
vm.orders = []
vm.selectedItemsList = []
Expand Down Expand Up @@ -260,22 +260,6 @@ function ComponentController ($filter, $state, lodash, ListView, Language, Order
}
}

function getFilterCount () {
return new Promise((resolve, reject) => {
OrdersState.getMinimal(OrdersState.getFilters()).then(querySuccess, queryFailure)

function querySuccess (result) {
vm.filterCount = result.subcount
resolve()
}

function queryFailure (_error) {
EventNotifications.error(__('There was an error loading orders.'))
reject(__('There was an error loading orders.'))
}
})
}

function duplicateOrder (item) {
ShoppingCart.reset()
ShoppingCart.delete()
Expand All @@ -297,6 +281,7 @@ function ComponentController ($filter, $state, lodash, ListView, Language, Order
function checkApproval () {
return lodash.reduce(lodash.map(['miq_request_approval', 'miq_request_admin'], RBAC.has))
}

function requestStatus (item) {
let status = item.request_state
if ((item.request_state === 'finished' && item.status !== 'Ok') || (item.request_state !== 'finished')) {
Expand Down
46 changes: 13 additions & 33 deletions client/app/services/service-explorer/service-explorer.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
title: __('Services'),
services: [],
limit: 20,
filterCount: 0,
servicesList: [],
selectedItemsList: [],
limitOptions: [5, 10, 20, 50, 100, 200, 500, 1000],
Expand Down Expand Up @@ -348,11 +347,11 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
}
if (tag.name.match(/\//g).length === 3) {
filterCategories[tag.name.substring(-1, tag.name.lastIndexOf('/'))]
.filterValues
.push({
title: displayName.substr(displayName.lastIndexOf(':') + 1),
id: tag.name.substr(tag.name.lastIndexOf('/') + 1)
})
.filterValues
.push({
title: displayName.substr(displayName.lastIndexOf(':') + 1),
id: tag.name.substr(tag.name.lastIndexOf('/') + 1)
})
}
})

Expand Down Expand Up @@ -383,37 +382,18 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
]
}

function getFilterCount () {
return new Promise((resolve, reject) => {
ServicesState.getServicesMinimal(ServicesState.services.getFilters())
.then(querySuccess, queryFailure)

function querySuccess (result) {
vm.filterCount = result.subcount
vm.toolbarConfig.filterConfig.resultsCount = vm.filterCount
resolve()
}

function queryFailure (_error) {
vm.loading = false
EventNotifications.error(__('There was an error loading the services.'))
reject(__('There was an error loading the services.'))
}
})
}

function resolveServices (limit, offset, refresh) {
Polling.stop('serviceListPolling')
vm.loading = !refresh
vm.offset = offset
getFilterCount().then(() => {
ServicesState.getServices(
limit,
offset,
refresh).then(querySuccess, queryFailure)
})

ServicesState.getServices(
limit,
offset,
refresh).then(querySuccess, queryFailure)

function querySuccess (result) {
vm.toolbarConfig.filterConfig.resultsCount = result.subquery_count
Polling.start('serviceListPolling', pollUpdateServicesList, vm.pollingInterval)
vm.services = []
var existingServices = (angular.isDefined(vm.servicesList) && refresh ? angular.copy(vm.servicesList) : [])
Expand Down Expand Up @@ -513,8 +493,8 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
lodash.partial(TagEditorModal.showModal, services)

return TaggingService.queryAvailableTags()
.then(extractSharedTagsFromSelectedServices)
.then(launchTagEditorForSelectedServices)
.then(extractSharedTagsFromSelectedServices)
.then(launchTagEditorForSelectedServices)
}

function doRemoveServices (services) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,19 @@ describe('Component: serviceExplorer', () => {

it('should make a query for services', () => {
collectionsApiMock
.expects('query')
.withArgs('services', {filter: ['ancestry=null']})
.returns(Promise.resolve())
.expects('query')
.withArgs('services', {
attributes: ['picture', 'picture.image_href', 'chargeback_report', 'evm_owner.userid', 'v_total_vms', 'power_state', 'all_service_children', 'tags'],
auto_refresh: undefined,
expand: 'resources',
filter: ['ancestry=null'],
limit: 20,
offset: '0',
sort_by: 'created_at',
sort_options: '',
sort_order: 'desc'
})
.returns(Promise.resolve())

ctrl.resolveServices(20, 0)

Expand Down
Loading

0 comments on commit 13a3614

Please sign in to comment.