Skip to content

Commit

Permalink
Improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasstein committed Feb 5, 2025
1 parent a70589a commit 4ab3b1c
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
///

import { Mutable, properties } from "apprt-core/Mutable";
import { Layout, Pagination, PortalItem, PortalType, SortByField, SpaceFilter, VisibleElements } from "./api";
import { Layout, Pagination, PortalItem, PortalType, SortByField, SpaceFilter, VisibleElements, TypeFilter } from "./api";

function defineProperties<Impl, P>(mutableDefinition: any, mutableProperties: P): Impl & Mutable<P> {
properties(mutableDefinition, mutableProperties);
Expand All @@ -40,9 +40,9 @@ interface PortalItemLoaderModelProps {
spaceFilters: any[],
spaceFiltersPortal: any[],
typeFilter: string,
typeFilters: any[],
typeFiltersPortal: any[],
typeFiltersCSW: any[],
typeFilters: TypeFilter[],
typeFiltersPortal: TypeFilter[],
typeFiltersCSW: TypeFilter[],
sortAscending: boolean,
sortByField: SortByField,
sortByFields: any[],
Expand Down
5 changes: 5 additions & 0 deletions src/main/js/bundles/dn_portalitemloader/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ export interface VisibleElements {
views: boolean,
modified: boolean
}

export interface TypeFilter {
id: string,
title: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,24 @@
</v-toolbar>
</div>
</template>
<script>
import { PortalType, SpaceFilter, VisibleElements } from "../api";
<script lang="ts">
import type { Portal, PortalType, SpaceFilter, VisibleElements, Layout, TypeFilter } from "../api";

export default {
props: {
i18n: {
type: Object,
default: () => {
default: (): any => {
return {};
}
},
layout: {
type: String,
default: ""
type: String as () => Layout,
default: "grid"
},
portals: {
type: Array,
default: () => []
default: (): Array<Portal> => []
},
authenticated: {
type: Boolean,
Expand All @@ -191,24 +191,24 @@
default: ""
},
selectedPortalType: {
type: PortalType,
type: String as () => PortalType,
default: ""
},
spaceFilter: {
type: SpaceFilter,
type: String as () => SpaceFilter,
default: "all"
},
spaceFilters: {
type: Array,
default: () => []
default: (): Array<SpaceFilter> => []
},
typeFilter: {
type: String,
default: () => ""
default: (): string => ""
},
typeFilters: {
type: Array,
default: () => []
default: (): Array<TypeFilter> => []
},
sortAscending: {
type: Boolean,
Expand All @@ -220,15 +220,15 @@
},
sortByFields: {
type: Array,
default: () => []
default: (): Array<string> => []
},
isMobile: {
type: Boolean,
default: false
},
visibleElements: {
type: VisibleElements,
default: () => {
type: Object as () => VisibleElements,
default: (): VisibleElements => {
return {
sortBy: true,
typeFilter: true,
Expand All @@ -241,90 +241,90 @@
}
}
},
data() {
data(): any {
return {
filterVisible: false
};
},
computed: {
allTypesSelected() {
allTypesSelected(): boolean {
return this.typeFilter.length === this.typeFilters.length;
},
filterText() {
filterText(): string {
if(this.filterVisible) {
return this.i18n.hideFilters;
} else {
return this.i18n.showFilters;
}
},
filterAvailable() {
filterAvailable(): boolean {
return this.authenticated ||
(this.typeFilters.length && this.visibleElements.typeFilter) || this.visibleElements.sortBy;
},
localLayout: {
get: function () {
get: function (): Layout {
return this.layout;
},
set: function (layout) {
set: function (layout: Layout): void {
this.$emit("update:layout", layout);
}
},
localSearchText: {
get: function () {
get: function (): string {
return this.searchText;
},
set: function (searchText) {
set: function (searchText: string): void {
this.$emit("update:search-text", searchText);
}
},
localPortalFilter: {
get: function () {
get: function (): string {
return this.portalFilter;
},
set: function (portalFilter) {
set: function (portalFilter: string): void {
this.$emit("update:portal-filter", portalFilter);
}
},
localSortByField: {
get: function () {
get: function (): string {
return this.sortByField;
},
set: function (sortByField) {
set: function (sortByField: string): void {
this.$emit("update:sort-by-field", sortByField);
}
},
localSortAscending: {
get: function () {
get: function (): boolean {
return this.sortAscending;
},
set: function (sortAscending) {
set: function (sortAscending: boolean): void {
this.$emit("update:sort-ascending", sortAscending);
}
},
localSpaceFilter: {
get: function () {
get: function (): SpaceFilter {
return this.spaceFilter;
},
set: function (spaceFilter) {
set: function (spaceFilter: SpaceFilter): void {
this.$emit("update:space-filter", spaceFilter);
}
},
localTypeFilter: {
get: function () {
get: function (): string {
return this.typeFilter;
},
set: function (typeFilter) {
set: function (typeFilter: string): void {
this.$emit("update:type-filter", typeFilter);
}
}
},
methods: {
toggle () {
toggle(): void {
this.$nextTick(() => {
if (this.allTypesSelected) {
this.localTypeFilter = [];
} else {
this.localTypeFilter = this.typeFilters.map((type)=>type.id);
this.localTypeFilter = this.typeFilters.map((type: TypeFilter) => type.id);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</v-card-actions>
</v-card>
</template>
<script>
<script lang="ts">
import moment from 'moment';
import * as intl from "esri/intl";
import { PortalItem, VisibleElements } from "../api";
Expand All @@ -173,19 +173,35 @@
props: {
i18n: {
type: Object,
default: () => {
default: (): any => {
return {};
}
},
item: {
type: PortalItem,
default: () => {
return {};
type: Object as () => PortalItem,
default: (): PortalItem => {
return {
id: '',
title: '',
snippet: '',
description: '',
thumbnailUrl: '',
tags: [],
owner: '',
numViews: 0,
created: new Date(),
modified: new Date(),
type: '',
url: '',
itemPageUrl: '',
portalUrl: '',
source: "portal"
};
}
},
visibleElements: {
type: VisibleElements,
default: () => {
type: Object as () => VisibleElements,
default: (): VisibleElements => {
return {
sortBy: true,
typeFilter: true,
Expand All @@ -199,15 +215,15 @@
}
},
computed: {
modified() {
modified(): string | undefined {
const modified = moment(this.item.modified);
if(modified.isValid()) {
return moment(modified).format("DD.MM.YYYY");
} else {
return undefined;
}
},
views() {
views(): string {
const numberFormatIntlOptions = intl.convertNumberFormatToIntlOptions({
digitSeparator: true
});
Expand Down
Loading

0 comments on commit 4ab3b1c

Please sign in to comment.