Skip to content

Commit

Permalink
update authentification
Browse files Browse the repository at this point in the history
  • Loading branch information
Lia Kirsch committed Nov 14, 2024
1 parent aa5b4e4 commit 22ce1cb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
46 changes: 31 additions & 15 deletions src/main/js/bundles/dn_portalcontent/PortalContentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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
};
Expand Down
8 changes: 7 additions & 1 deletion src/main/js/bundles/dn_portalcontent/PortalContentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ function defineProperties<Impl, P>(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[],
pagination: object,
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",
Expand All @@ -42,6 +45,7 @@ interface PortalContentModelProps {
export default defineProperties<PortalContentModel, PortalContentModelProps>(PortalContentModel, {
portals: [],
portalItems: [],
authenticated: false,
loading: false,
totalItems: 0,
rowsPerPageItems: [
Expand All @@ -55,6 +59,8 @@ export default defineProperties<PortalContentModel, PortalContentModelProps>(Por
portalFilter: "",
spaceFilters: [],
spaceFilter: "all",
typeFilter: "all",
typeFilters: ["Feature Service", "Vector Tile Service", "Image Service", "Scene Service"],
searchText: "",
sortAscending: false,
sortByField: "modified",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
hide-details
/>
<v-select
v-if="authenticated"
v-model="localSpaceFilter"
class="pb-2"
item-value="id"
Expand Down Expand Up @@ -103,6 +104,10 @@
type: Array,
default: () => []
},
authenticated: {
type: Boolean,
default: false
},
searchText: {
type: String,
default: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<filter-widget
:i18n="i18n"
:portals="portals"
:authenticated="authenticated"
:space-filters="spaceFilters"
:sort-by-fields="sortByFields"
:search-text.sync="searchText"
Expand Down Expand Up @@ -102,6 +103,10 @@
type: Array,
default: () => []
},
authenticated: {
type: Boolean,
default: false
},
loading: {
type: Boolean,
default: false
Expand Down

0 comments on commit 22ce1cb

Please sign in to comment.