diff --git a/src/main/js/bundles/dn_portalcontent/PortalContentController.ts b/src/main/js/bundles/dn_portalcontent/PortalContentController.ts index c895aed..d90a520 100644 --- a/src/main/js/bundles/dn_portalcontent/PortalContentController.ts +++ b/src/main/js/bundles/dn_portalcontent/PortalContentController.ts @@ -26,45 +26,50 @@ export default class PortalContentWidgetController { private readonly portalContentModel: typeof PortalContentModel; private lastTimeout: any; private abortController: AbortController; + private portal: __esri.Portal; constructor(i18n: any, mapWidgetModel: MapWidgetModel, portalContentModel: typeof PortalContentModel) { this.mapWidgetModel = mapWidgetModel; const model = this.portalContentModel = portalContentModel; model.portalFilter = model.portals[0].id; + this.changeSelectedPortal(model.portalFilter); portalContentModel.watch("portalFilter", ({ value }) => { + // delete current results model.portalItems = []; - this.queryPortalItems(model.pagination, value, model.searchText, model.spaceFilter, + // set new portal + this.changeSelectedPortal(value); + this.queryPortalItems(model.pagination, this.portal, model.searchText, model.spaceFilter, model.sortAscending, model.sortByField); }); portalContentModel.watch("searchText", ({ value }) => { - this.queryPortalItems(model.pagination, model.portalFilter, value, model.spaceFilter, + this.queryPortalItems(model.pagination, this.portal, value, model.spaceFilter, model.sortAscending, model.sortByField); }); portalContentModel.watch("pagination", ({ value }) => { - this.queryPortalItems(value, model.portalFilter, model.searchText, model.spaceFilter, + this.queryPortalItems(value, this.portal, model.searchText, model.spaceFilter, model.sortAscending, model.sortByField); }); portalContentModel.watch("spaceFilter", ({ value }) => { - this.queryPortalItems(model.pagination, model.portalFilter, model.searchText, value, + this.queryPortalItems(model.pagination, this.portal, model.searchText, value, model.sortAscending, model.sortByField); }); portalContentModel.watch("sortAscending", ({ value }) => { - this.queryPortalItems(model.pagination, model.portalFilter, model.searchText, model.spaceFilter, + this.queryPortalItems(model.pagination, this.portal, model.searchText, model.spaceFilter, value, model.sortByField); }); portalContentModel.watch("sortByField", ({ value }) => { - this.queryPortalItems(model.pagination, model.portalFilter, model.searchText, model.spaceFilter, + this.queryPortalItems(model.pagination, this.portal, model.searchText, model.spaceFilter, model.sortAscending, value); }); } - queryPortalItems(pagination: any, portalFilter: string, searchText: string, spaceFilter: "all" | "organisation" | "my-content", + queryPortalItems(pagination: any, portal: __esri.Portal, searchText: string, spaceFilter: "all" | "organisation" | "my-content", sortAscending: boolean, sortByField: Fields): void { const model = this.portalContentModel; @@ -74,9 +79,8 @@ export default class PortalContentWidgetController { if (this.abortController) { this.abortController.abort(); } - const selectedPortal = model.portals.find((portalConfig) => portalConfig.id === model.portalFilter); const promise = - this.queryPortal(selectedPortal, pagination, searchText, spaceFilter, sortAscending, sortByField); + this.queryPortal(portal, pagination, searchText, spaceFilter, sortAscending, sortByField); promise.then((result) => { this.abortController = null; model.loading = false; @@ -89,15 +93,28 @@ export default class PortalContentWidgetController { }, 500); } - private queryPortal(portalConfig: any, pagination: any, searchText: string, spaceFilter: "all" | "organisation" | "my-content", + private changeSelectedPortal(portalId: string) { + const model = this.portalContentModel; + const selectedPortal = model.portals.find((portalConfig) => portalConfig.id === portalId); + const portal = this.portal = new Portal(selectedPortal.url); + portal.load().then(() => { + if (portal.user) { + model.authenticated = true; + } else { + model.authenticated = false; + } + }); + } + + private queryPortal(portal: __esri.Portal, pagination: any, searchText: string, spaceFilter: "all" | "organisation" | "my-content", sortAscending: boolean, sortByField: Fields): Promise<__esri.PortalQueryResult> { const page = pagination.page; const rowsPerPage = pagination.rowsPerPage; - const portal = new Portal(portalConfig.url); return new Promise(resolve => { portal.load().then(() => { - let query; + let query = ""; + let filter = "typeKeywords:Service"; switch (spaceFilter) { case "all": query = "1=1"; @@ -109,14 +126,13 @@ export default class PortalContentWidgetController { query = "owner:" + portal.user.username; } if (searchText !== "") { - query += " AND title:" + searchText; + query += "AND (title:" + searchText + " OR description:" + searchText + " OR snippet:" + searchText + ")"; } const queryParams: __esri.PortalQueryParamsProperties = { query: query, sortField: sortByField, sortOrder: sortAscending ? "asc" : "desc", - filter: 'typeKeywords:Service', - // filter: 'type:"Feature Service"', + filter: filter, num: rowsPerPage, start: page * rowsPerPage - rowsPerPage + 1 }; diff --git a/src/main/js/bundles/dn_portalcontent/PortalContentModel.ts b/src/main/js/bundles/dn_portalcontent/PortalContentModel.ts index e5ef204..657b273 100644 --- a/src/main/js/bundles/dn_portalcontent/PortalContentModel.ts +++ b/src/main/js/bundles/dn_portalcontent/PortalContentModel.ts @@ -21,11 +21,12 @@ function defineProperties(mutableDefinition: any, mutableProperties: P) return mutableDefinition; } -class PortalContentModel extends Mutable {} +class PortalContentModel extends Mutable { } interface PortalContentModelProps { portals: any[], portalItems: __esri.PortalItem[], + authenticated: boolean, loading: boolean, totalItems: number, rowsPerPageItems: number[], @@ -33,6 +34,8 @@ interface PortalContentModelProps { portalFilter: string, spaceFilters: any[], spaceFilter: "all" | "organisation" | "my-content", + typeFilter: string, + typeFilters: any[], searchText: "", sortAscending: boolean, sortByField: "modified" | "title" | "uploaded" | "username" | "created" | "type" | "owner" | "avg-rating" | "num-ratings" | "num-comments" | "num-views", @@ -42,6 +45,7 @@ interface PortalContentModelProps { export default defineProperties(PortalContentModel, { portals: [], portalItems: [], + authenticated: false, loading: false, totalItems: 0, rowsPerPageItems: [ @@ -55,6 +59,8 @@ export default defineProperties(Por portalFilter: "", spaceFilters: [], spaceFilter: "all", + typeFilter: "all", + typeFilters: ["Feature Service", "Vector Tile Service", "Image Service", "Scene Service"], searchText: "", sortAscending: false, sortByField: "modified", diff --git a/src/main/js/bundles/dn_portalcontent/PortalContentWidgetFactory.ts b/src/main/js/bundles/dn_portalcontent/PortalContentWidgetFactory.ts index a74f0fa..5060b46 100644 --- a/src/main/js/bundles/dn_portalcontent/PortalContentWidgetFactory.ts +++ b/src/main/js/bundles/dn_portalcontent/PortalContentWidgetFactory.ts @@ -85,7 +85,7 @@ export default class PortalContentWidgetFactory { this.binding = Binding.for(vm, model) .syncAll("portalFilter") - .syncAllToLeft("portalItems", "totalItems", "loading") + .syncAllToLeft("portalItems", "totalItems", "loading", "authenticated") .syncAllToRight("pagination", "searchText", "sortByField", "sortAscending", "spaceFilter"); } diff --git a/src/main/js/bundles/dn_portalcontent/templates/FilterWidget.vue b/src/main/js/bundles/dn_portalcontent/templates/FilterWidget.vue index 437ae80..64ffcf9 100644 --- a/src/main/js/bundles/dn_portalcontent/templates/FilterWidget.vue +++ b/src/main/js/bundles/dn_portalcontent/templates/FilterWidget.vue @@ -43,6 +43,7 @@ hide-details /> [] }, + authenticated: { + type: Boolean, + default: false + }, searchText: { type: String, default: "" diff --git a/src/main/js/bundles/dn_portalcontent/templates/PortalContentWidget.vue b/src/main/js/bundles/dn_portalcontent/templates/PortalContentWidget.vue index be79be0..bf0c934 100644 --- a/src/main/js/bundles/dn_portalcontent/templates/PortalContentWidget.vue +++ b/src/main/js/bundles/dn_portalcontent/templates/PortalContentWidget.vue @@ -21,6 +21,7 @@ [] }, + authenticated: { + type: Boolean, + default: false + }, loading: { type: Boolean, default: false