@beinformed/ui 1.60.1 → 1.60.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/esm/hooks/__tests__/useModelCatalog.spec.js.flow +0 -2
- package/esm/hooks/useModelCatalog.d.ts +1 -1
- package/esm/hooks/useModelCatalog.js +4 -4
- package/esm/hooks/useModelCatalog.js.flow +5 -5
- package/esm/hooks/useModelCatalog.js.map +1 -1
- package/esm/models/attributes/ChoiceAttributeOptionCollection.d.ts +6 -0
- package/esm/models/attributes/ChoiceAttributeOptionCollection.js +19 -6
- package/esm/models/attributes/ChoiceAttributeOptionCollection.js.flow +12 -0
- package/esm/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
- package/esm/models/concepts/__tests__/ConceptIndexModel.spec.js.flow +4 -0
- package/esm/models/filters/ConceptIndexFilterModel.js +9 -8
- package/esm/models/filters/ConceptIndexFilterModel.js.flow +15 -11
- package/esm/models/filters/ConceptIndexFilterModel.js.map +1 -1
- package/esm/models/form/__tests__/FormModel.spec.js.flow +2 -0
- package/esm/modularui/UploadRequest.js +5 -4
- package/esm/modularui/UploadRequest.js.flow +16 -6
- package/esm/modularui/UploadRequest.js.map +1 -1
- package/lib/hooks/useModelCatalog.d.ts +1 -1
- package/lib/hooks/useModelCatalog.js +4 -4
- package/lib/hooks/useModelCatalog.js.map +1 -1
- package/lib/models/attributes/ChoiceAttributeOptionCollection.d.ts +6 -0
- package/lib/models/attributes/ChoiceAttributeOptionCollection.js +19 -6
- package/lib/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
- package/lib/models/filters/ConceptIndexFilterModel.js +9 -8
- package/lib/models/filters/ConceptIndexFilterModel.js.map +1 -1
- package/lib/modularui/UploadRequest.js +4 -3
- package/lib/modularui/UploadRequest.js.map +1 -1
- package/package.json +5 -5
- package/src/hooks/__tests__/useModelCatalog.spec.js +0 -2
- package/src/hooks/useModelCatalog.js +5 -5
- package/src/models/attributes/ChoiceAttributeOptionCollection.js +12 -0
- package/src/models/concepts/__mock__/conceptindex_data.json +8 -2
- package/src/models/concepts/__tests__/ConceptIndexModel.spec.js +4 -0
- package/src/models/filters/ConceptIndexFilterModel.js +15 -11
- package/src/models/form/__tests__/FormModel.spec.js +2 -0
- package/src/modularui/UploadRequest.js +16 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.60.3](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.60.2...v1.60.3) (2025-03-06)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **concepts:** prevent duplicate characters in concept index filter ([108cea9](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/108cea96907757b6dd5ec604cdb4bd65962db74e))
|
|
11
|
+
* **concepts:** useContent can also return a ContentTOC ([bf59992](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/bf599922e93de615c2f11b6873beee2edf13ec9f))
|
|
12
|
+
|
|
13
|
+
## [1.60.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.60.1...v1.60.2) (2025-03-03)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **upload:** improve error handling on form uploads ([134de76](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/134de76b6b10dbcaecdd007fe27afc0a9a2a80f6))
|
|
19
|
+
|
|
5
20
|
## [1.60.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.60.0...v1.60.1) (2025-02-19)
|
|
6
21
|
|
|
7
22
|
|
|
@@ -8,7 +8,6 @@ import { useLocation } from "react-router";
|
|
|
8
8
|
import {
|
|
9
9
|
ConceptIndexModel,
|
|
10
10
|
ContentIndexModel,
|
|
11
|
-
ContentModel,
|
|
12
11
|
ContentTypeModel,
|
|
13
12
|
ContentTOCModel,
|
|
14
13
|
Href,
|
|
@@ -147,7 +146,6 @@ describe("modelcatalog hooks", () => {
|
|
|
147
146
|
() => useContent("/contentdetail"),
|
|
148
147
|
"content",
|
|
149
148
|
"/content/contentdetail?entryDate=" + DateUtil.now(),
|
|
150
|
-
ContentModel,
|
|
151
149
|
);
|
|
152
150
|
});
|
|
153
151
|
|
|
@@ -10,7 +10,7 @@ export function useConceptIndex(href: string | Href, key?: string, options?: Use
|
|
|
10
10
|
export function useConceptDetail(concept: string | Href, key?: string, options?: UseModularUIBasicOptions<ConceptDetailModel | BusinessScenarioModel>): (ConceptDetailModel | (BusinessScenarioModel | null)) | null;
|
|
11
11
|
export function useContentIndex(href: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentIndexModel>): ContentIndexModel | null;
|
|
12
12
|
export function useContentTOC(content: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentTOCModel>): ContentTOCModel | null;
|
|
13
|
-
export function useContent(
|
|
13
|
+
export function useContent(content: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentModel>): (ContentModel | (ContentTOCModel | null)) | null;
|
|
14
14
|
export function useContentType(contentType: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentTypeModel>): ContentTypeModel | null;
|
|
15
15
|
export function useConceptSearch(filters: SearchFilter, key?: string, options?: UseModularUIBasicOptions<ConceptIndexModel>): ConceptIndexModel | null;
|
|
16
16
|
export function useContentSearch(filters: SearchFilter, key?: string, options?: UseModularUIBasicOptions<ContentIndexModel>): ContentIndexModel | null;
|
|
@@ -86,16 +86,16 @@ export const useContentTOC = function (content) {
|
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
*/
|
|
89
|
-
export const useContent = function (
|
|
89
|
+
export const useContent = function (content) {
|
|
90
90
|
let key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "content";
|
|
91
91
|
let options = arguments.length > 2 ? arguments[2] : undefined;
|
|
92
92
|
const {
|
|
93
93
|
entryDate
|
|
94
94
|
} = useEntryDate();
|
|
95
|
-
const
|
|
95
|
+
const location = useLocation();
|
|
96
|
+
const href = createHref("content", content, entryDate, location, []);
|
|
96
97
|
return useModularUIBasic(key, href, {
|
|
97
|
-
expectedModels: ["Content"],
|
|
98
|
-
targetModel: ContentModel,
|
|
98
|
+
expectedModels: ["Content", "ContentTOC"],
|
|
99
99
|
...options
|
|
100
100
|
});
|
|
101
101
|
};
|
|
@@ -120,17 +120,17 @@ export const useContentTOC = (
|
|
|
120
120
|
/**
|
|
121
121
|
*/
|
|
122
122
|
export const useContent = (
|
|
123
|
-
|
|
123
|
+
content: string | Href,
|
|
124
124
|
key?: string = "content",
|
|
125
125
|
options?: UseModularUIBasicOptions<ContentModel>,
|
|
126
|
-
): ?ContentModel => {
|
|
126
|
+
): ?ContentModel | ?ContentTOCModel => {
|
|
127
127
|
const { entryDate } = useEntryDate();
|
|
128
|
+
const location = useLocation();
|
|
128
129
|
|
|
129
|
-
const href = createHref("content",
|
|
130
|
+
const href = createHref("content", content, entryDate, location, []);
|
|
130
131
|
|
|
131
132
|
return useModularUIBasic(key, href, {
|
|
132
|
-
expectedModels: ["Content"],
|
|
133
|
-
targetModel: ContentModel,
|
|
133
|
+
expectedModels: ["Content", "ContentTOC"],
|
|
134
134
|
...options,
|
|
135
135
|
});
|
|
136
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModelCatalog.js","names":["useSelector","useDispatch","useLocation","createHref","filterParameters","ModelCatalogModel","ConceptIndexModel","ConceptDetailModel","default","BusinessScenarioModel","ContentIndexModel","ContentTOCModel","ContentModel","useModularUIBasic","ContentTypeModel","getEntryDate","updateEntryDate","useModelCatalog","options","expectedModels","targetModel","useConceptIndex","href","key","arguments","length","undefined","entryDate","useEntryDate","url","setParameter","useConceptDetail","concept","location","useContentIndex","useContentTOC","content","useContent","contentSection","useContentType","contentType","getSearchHref","uri","filters","filterString","_Object$keys","filterValue","value","Array","isArray","join","replace","push","useConceptSearch","useContentSearch","dispatch","setEntryDate"],"sources":["../../src/hooks/useModelCatalog.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\nimport { useLocation } from \"./useRouter\";\n\nimport { createHref, filterParameters } from \"../utils/helpers/createHref\";\n\nimport ModelCatalogModel from \"../models/modelcatalog/ModelCatalogModel\";\nimport ConceptIndexModel from \"../models/concepts/ConceptIndexModel\";\nimport ConceptDetailModel from \"../models/concepts/ConceptDetailModel\";\nimport { default as BusinessScenarioModel } from \"../models/concepts/BusinessScenarioModel\";\nimport ContentIndexModel from \"../models/content/ContentIndexModel\";\nimport ContentTOCModel from \"../models/content/ContentTOCModel\";\nimport ContentModel from \"../models/content/ContentModel\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\nimport { ContentTypeModel } from \"../models\";\n\nimport { getEntryDate } from \"../redux/selectors/modelcatalog\";\nimport { updateEntryDate } from \"../redux/actions/ModelCatalog\";\n\nimport type Href from \"../models/href/Href\";\nimport type { UseModularUIBasicOptions } from \"./useModularUIBasic\";\nimport type { UpdateEntryDateAction } from \"../redux\";\nexport type SearchFilter = {\n index?: string,\n label?: string,\n type?: string | Array<string>,\n modelCategory?: string | Array<string>,\n entryDate?: string,\n};\n\n/**\n */\nexport const useModelCatalog = (\n options?: UseModularUIBasicOptions<ModelCatalogModel>,\n): ?ModelCatalogModel =>\n useModularUIBasic(\"modelcatalog\", \"/modelcatalog\", {\n expectedModels: [\"ModelCatalog\"],\n targetModel: ModelCatalogModel,\n ...options,\n });\n\n/**\n */\nexport const useConceptIndex = (\n href: string | Href,\n key?: string = \"conceptindex\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const { entryDate } = useEntryDate();\n const url = filterParameters(href, [\n \"index\",\n \"label\",\n \"modelcategory\",\n \"type\",\n ]);\n url.setParameter(\"entryDate\", entryDate);\n\n return useModularUIBasic(key, url, {\n expectedModels: [\"ConceptIndex\"],\n targetModel: ConceptIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useConceptDetail = (\n concept: string | Href,\n key?: string = \"conceptdetail\",\n options?: UseModularUIBasicOptions<\n ConceptDetailModel | BusinessScenarioModel,\n >,\n): ?ConceptDetailModel | ?BusinessScenarioModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"concepts\", concept, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ConceptDetail\", \"BusinessScenario\"],\n ...options,\n });\n};\n\n/**\n */\nexport const useContentIndex = (\n href: string | Href,\n key?: string = \"contentindex\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const url = filterParameters(href, [\"index\", \"label\", \"type\"]);\n return useModularUIBasic(key, url, {\n expectedModels: [\"ContentIndex\"],\n targetModel: ContentIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContentTOC = (\n content: string | Href,\n key?: string = \"contenttoc\",\n options?: UseModularUIBasicOptions<ContentTOCModel>,\n): ?ContentTOCModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"content\", content, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentTOC\"],\n targetModel: ContentTOCModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContent = (\n contentSection: string | Href,\n key?: string = \"content\",\n options?: UseModularUIBasicOptions<ContentModel>,\n): ?ContentModel => {\n const { entryDate } = useEntryDate();\n\n const href = createHref(\"content\", contentSection, entryDate, null, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"Content\"],\n targetModel: ContentModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContentType = (\n contentType: string | Href,\n key?: string = \"contenttypes\",\n options?: UseModularUIBasicOptions<ContentTypeModel>,\n): ?ContentTypeModel => {\n const href = createHref(\"contenttypes\", contentType, null, null, []);\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentType\"],\n targetModel: ContentTypeModel,\n ...options,\n });\n};\n\n/**\n */\nconst getSearchHref = (uri: string, filters: SearchFilter): string => {\n const filterString = [];\n\n for (const key of Object.keys(filters)) {\n const filterValue = filters[key];\n if (filterValue) {\n let value: string = Array.isArray(filterValue)\n ? filterValue.join(\",\")\n : filterValue;\n if (key === \"type\") {\n value = value.replace(\"#\", \"%23\"); // handles un-encoded #\n }\n filterString.push(`${key}=${value}`);\n }\n }\n\n return filterString.length ? `${uri}?${filterString.join(\"&\")}` : uri;\n};\n\n/**\n */\nexport const useConceptSearch = (\n filters: SearchFilter,\n key?: string = \"conceptSearch\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const href = getSearchHref(\"/concepts\", filters);\n return useConceptIndex(href, key, options);\n};\n\n/**\n */\nexport const useContentSearch = (\n filters: SearchFilter,\n key?: string = \"contentSearch\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const href = getSearchHref(\"/content\", filters);\n return useContentIndex(href, key, options);\n};\n\n/**\n * Retrieve and update the entrydate for the modelcatalog\n */\nexport const useEntryDate = (): ({\n entryDate: ISO_DATE,\n setEntryDate: (entryDate: ISO_DATE) => UpdateEntryDateAction,\n}) => {\n const dispatch = useDispatch();\n const entryDate = useSelector(getEntryDate);\n\n return {\n entryDate,\n setEntryDate: (entryDate: ISO_DATE) => dispatch(updateEntryDate(entryDate)),\n };\n};\n"],"mappings":";AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,UAAU,EAAEC,gBAAgB,QAAQ,6BAA6B;AAE1E,OAAOC,iBAAiB,MAAM,0CAA0C;AACxE,OAAOC,iBAAiB,MAAM,sCAAsC;AACpE,OAAOC,kBAAkB,MAAM,uCAAuC;AACtE,SAASC,OAAO,IAAIC,qBAAqB,QA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AAe,CAACC,IAAI,EAAEC,GAAG,EAAEL,OAAO,CAAC;AAC5C,CAAC;;AAED;AACA;AACA,OAAO,MAAMoC,gBAAgB,GAAG,SAAAA,CAC9BX,OAAqB,EAGE;EAAA,IAFvBpB,GAAY,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,eAAe;EAAA,IAC9BN,OAAqD,GAAAM,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAErD,MAAMJ,IAAI,GAAGmB,aAAa,CAAC,UAAU,EAAEE,OAAO,CAAC;EAC/C,OAAOT,eAAe,CAACZ,IAAI,EAAEC,GAAG,EAAEL,OAAO,CAAC;AAC5C,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMU,YAAY,GAAGA,CAAA,KAGtB;EACJ,MAAM2B,QAAQ,GAAGtD,WAAW,CAAC,CAAC;EAC9B,MAAM0B,SAAS,GAAG3B,WAAW,CAACe,YAAY,CAAC;EAE3C,OAAO;IACLY,SAAS;IACT6B,YAAY,EAAG7B,SAAmB,IAAK4B,QAAQ,CAACvC,eAAe,CAACW,SAAS,CAAC;EAC5E,CAAC;AACH,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useModelCatalog.js","names":["useSelector","useDispatch","useLocation","createHref","filterParameters","ModelCatalogModel","ConceptIndexModel","ConceptDetailModel","default","BusinessScenarioModel","ContentIndexModel","ContentTOCModel","ContentModel","useModularUIBasic","ContentTypeModel","getEntryDate","updateEntryDate","useModelCatalog","options","expectedModels","targetModel","useConceptIndex","href","key","arguments","length","undefined","entryDate","useEntryDate","url","setParameter","useConceptDetail","concept","location","useContentIndex","useContentTOC","content","useContent","useContentType","contentType","getSearchHref","uri","filters","filterString","_Object$keys","filterValue","value","Array","isArray","join","replace","push","useConceptSearch","useContentSearch","dispatch","setEntryDate"],"sources":["../../src/hooks/useModelCatalog.js"],"sourcesContent":["// @flow\nimport { useSelector, useDispatch } from \"react-redux\";\nimport { useLocation } from \"./useRouter\";\n\nimport { createHref, filterParameters } from \"../utils/helpers/createHref\";\n\nimport ModelCatalogModel from \"../models/modelcatalog/ModelCatalogModel\";\nimport ConceptIndexModel from \"../models/concepts/ConceptIndexModel\";\nimport ConceptDetailModel from \"../models/concepts/ConceptDetailModel\";\nimport { default as BusinessScenarioModel } from \"../models/concepts/BusinessScenarioModel\";\nimport ContentIndexModel from \"../models/content/ContentIndexModel\";\nimport ContentTOCModel from \"../models/content/ContentTOCModel\";\nimport ContentModel from \"../models/content/ContentModel\";\n\nimport { useModularUIBasic } from \"./useModularUIBasic\";\nimport { ContentTypeModel } from \"../models\";\n\nimport { getEntryDate } from \"../redux/selectors/modelcatalog\";\nimport { updateEntryDate } from \"../redux/actions/ModelCatalog\";\n\nimport type Href from \"../models/href/Href\";\nimport type { UseModularUIBasicOptions } from \"./useModularUIBasic\";\nimport type { UpdateEntryDateAction } from \"../redux\";\nexport type SearchFilter = {\n index?: string,\n label?: string,\n type?: string | Array<string>,\n modelCategory?: string | Array<string>,\n entryDate?: string,\n};\n\n/**\n */\nexport const useModelCatalog = (\n options?: UseModularUIBasicOptions<ModelCatalogModel>,\n): ?ModelCatalogModel =>\n useModularUIBasic(\"modelcatalog\", \"/modelcatalog\", {\n expectedModels: [\"ModelCatalog\"],\n targetModel: ModelCatalogModel,\n ...options,\n });\n\n/**\n */\nexport const useConceptIndex = (\n href: string | Href,\n key?: string = \"conceptindex\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const { entryDate } = useEntryDate();\n const url = filterParameters(href, [\n \"index\",\n \"label\",\n \"modelcategory\",\n \"type\",\n ]);\n url.setParameter(\"entryDate\", entryDate);\n\n return useModularUIBasic(key, url, {\n expectedModels: [\"ConceptIndex\"],\n targetModel: ConceptIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useConceptDetail = (\n concept: string | Href,\n key?: string = \"conceptdetail\",\n options?: UseModularUIBasicOptions<\n ConceptDetailModel | BusinessScenarioModel,\n >,\n): ?ConceptDetailModel | ?BusinessScenarioModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"concepts\", concept, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ConceptDetail\", \"BusinessScenario\"],\n ...options,\n });\n};\n\n/**\n */\nexport const useContentIndex = (\n href: string | Href,\n key?: string = \"contentindex\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const url = filterParameters(href, [\"index\", \"label\", \"type\"]);\n return useModularUIBasic(key, url, {\n expectedModels: [\"ContentIndex\"],\n targetModel: ContentIndexModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContentTOC = (\n content: string | Href,\n key?: string = \"contenttoc\",\n options?: UseModularUIBasicOptions<ContentTOCModel>,\n): ?ContentTOCModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"content\", content, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentTOC\"],\n targetModel: ContentTOCModel,\n ...options,\n });\n};\n\n/**\n */\nexport const useContent = (\n content: string | Href,\n key?: string = \"content\",\n options?: UseModularUIBasicOptions<ContentModel>,\n): ?ContentModel | ?ContentTOCModel => {\n const { entryDate } = useEntryDate();\n const location = useLocation();\n\n const href = createHref(\"content\", content, entryDate, location, []);\n\n return useModularUIBasic(key, href, {\n expectedModels: [\"Content\", \"ContentTOC\"],\n ...options,\n });\n};\n\n/**\n */\nexport const useContentType = (\n contentType: string | Href,\n key?: string = \"contenttypes\",\n options?: UseModularUIBasicOptions<ContentTypeModel>,\n): ?ContentTypeModel => {\n const href = createHref(\"contenttypes\", contentType, null, null, []);\n return useModularUIBasic(key, href, {\n expectedModels: [\"ContentType\"],\n targetModel: ContentTypeModel,\n ...options,\n });\n};\n\n/**\n */\nconst getSearchHref = (uri: string, filters: SearchFilter): string => {\n const filterString = [];\n\n for (const key of Object.keys(filters)) {\n const filterValue = filters[key];\n if (filterValue) {\n let value: string = Array.isArray(filterValue)\n ? filterValue.join(\",\")\n : filterValue;\n if (key === \"type\") {\n value = value.replace(\"#\", \"%23\"); // handles un-encoded #\n }\n filterString.push(`${key}=${value}`);\n }\n }\n\n return filterString.length ? `${uri}?${filterString.join(\"&\")}` : uri;\n};\n\n/**\n */\nexport const useConceptSearch = (\n filters: SearchFilter,\n key?: string = \"conceptSearch\",\n options?: UseModularUIBasicOptions<ConceptIndexModel>,\n): ?ConceptIndexModel => {\n const href = getSearchHref(\"/concepts\", filters);\n return useConceptIndex(href, key, options);\n};\n\n/**\n */\nexport const useContentSearch = (\n filters: SearchFilter,\n key?: string = \"contentSearch\",\n options?: UseModularUIBasicOptions<ContentIndexModel>,\n): ?ContentIndexModel => {\n const href = getSearchHref(\"/content\", filters);\n return useContentIndex(href, key, options);\n};\n\n/**\n * Retrieve and update the entrydate for the modelcatalog\n */\nexport const useEntryDate = (): ({\n entryDate: ISO_DATE,\n setEntryDate: (entryDate: ISO_DATE) => UpdateEntryDateAction,\n}) => {\n const dispatch = useDispatch();\n const entryDate = useSelector(getEntryDate);\n\n return {\n entryDate,\n setEntryDate: (entryDate: ISO_DATE) => dispatch(updateEntryDate(entryDate)),\n };\n};\n"],"mappings":";AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,aAAa;AACtD,SAASC,WAAW,QAAQ,aAAa;AAEzC,SAASC,UAAU,EAAEC,gBAAgB,QAAQ,6BAA6B;AAE1E,OAAOC,iBAAiB,MAAM,0CAA0C;AACxE,OAAOC,iBAAiB,MAAM,sCAAsC;AACpE,OAAOC,kBAAkB,MAAM,uCAAuC;AACtE,SAASC,OAAO,IAAIC,qBAAqB,QAAQ,0CAA0C;AAC3F,OAAOC,iBAAiB,MAAM,qCAAqC;AACnE,OAAOC,eAAe,MAAM,mCAAmC;AAC/D,OAAOC,YAAY,MAAM,gCAAgC;AAEzD,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,gBAAgB,QAA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vBnB,GAAY,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,eAAe;EAAA,IAC9BN,OAAqD,GAAAM,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAErD,MAAMJ,IAAI,GAAGkB,aAAa,CAAC,UAAU,EAAEE,OAAO,CAAC;EAC/C,OAAOR,eAAe,CAACZ,IAAI,EAAEC,GAAG,EAAEL,OAAO,CAAC;AAC5C,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMU,YAAY,GAAGA,CAAA,KAGtB;EACJ,MAAM0B,QAAQ,GAAGrD,WAAW,CAAC,CAAC;EAC9B,MAAM0B,SAAS,GAAG3B,WAAW,CAACe,YAAY,CAAC;EAE3C,OAAO;IACLY,SAAS;IACT4B,YAAY,EAAG5B,SAAmB,IAAK2B,QAAQ,CAACtC,eAAe,CAACW,SAAS,CAAC;EAC5E,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -39,6 +39,12 @@ declare class ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceA
|
|
|
39
39
|
/**
|
|
40
40
|
*/
|
|
41
41
|
addOption(data: string | Array<string>, contributions: Object): ChoiceAttributeOptionCollection;
|
|
42
|
+
/**
|
|
43
|
+
*/
|
|
44
|
+
getOptionByCode(code: string): ChoiceAttributeOptionModel | void;
|
|
45
|
+
/**
|
|
46
|
+
*/
|
|
47
|
+
hasOptionByCode(code: string): boolean;
|
|
42
48
|
/**
|
|
43
49
|
* Get all options that have selected property true
|
|
44
50
|
*/
|
|
@@ -160,6 +160,19 @@ class ChoiceAttributeOptionCollection extends ResourceCollection {
|
|
|
160
160
|
return this;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
*/
|
|
165
|
+
getOptionByCode(code) {
|
|
166
|
+
var _context4;
|
|
167
|
+
return _findInstanceProperty(_context4 = this.collection).call(_context4, option => option.code === code);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
*/
|
|
172
|
+
hasOptionByCode(code) {
|
|
173
|
+
return this.collection.some(option => option.code === code);
|
|
174
|
+
}
|
|
175
|
+
|
|
163
176
|
/**
|
|
164
177
|
* Get all options that have selected property true
|
|
165
178
|
*/
|
|
@@ -180,8 +193,8 @@ class ChoiceAttributeOptionCollection extends ResourceCollection {
|
|
|
180
193
|
* Deselect all options
|
|
181
194
|
*/
|
|
182
195
|
deselectAll() {
|
|
183
|
-
var
|
|
184
|
-
this.collection = _mapInstanceProperty(
|
|
196
|
+
var _context5;
|
|
197
|
+
this.collection = _mapInstanceProperty(_context5 = this.collection).call(_context5, option => {
|
|
185
198
|
const newOption = option.clone();
|
|
186
199
|
newOption.selected = false;
|
|
187
200
|
if (newOption.children) {
|
|
@@ -209,8 +222,8 @@ class ChoiceAttributeOptionCollection extends ResourceCollection {
|
|
|
209
222
|
* Toggle an option by it's code
|
|
210
223
|
*/
|
|
211
224
|
toggle(optionCode, action) {
|
|
212
|
-
var
|
|
213
|
-
this.collection = _mapInstanceProperty(
|
|
225
|
+
var _context6;
|
|
226
|
+
this.collection = _mapInstanceProperty(_context6 = this.collection).call(_context6, option => {
|
|
214
227
|
const newOption = option.clone();
|
|
215
228
|
if (newOption.code === optionCode) {
|
|
216
229
|
newOption.selected = action === "select";
|
|
@@ -224,8 +237,8 @@ class ChoiceAttributeOptionCollection extends ResourceCollection {
|
|
|
224
237
|
/**
|
|
225
238
|
*/
|
|
226
239
|
setReferenceDate(date) {
|
|
227
|
-
var
|
|
228
|
-
return _mapInstanceProperty(
|
|
240
|
+
var _context7;
|
|
241
|
+
return _mapInstanceProperty(_context7 = this.collection).call(_context7, option => {
|
|
229
242
|
option.referenceDate = date;
|
|
230
243
|
if (option.children) {
|
|
231
244
|
option.children.referenceDate = date;
|
|
@@ -202,6 +202,18 @@ class ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttribute
|
|
|
202
202
|
return this;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
*/
|
|
207
|
+
getOptionByCode(code: string): ChoiceAttributeOptionModel | void {
|
|
208
|
+
return this.collection.find((option) => option.code === code);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
*/
|
|
213
|
+
hasOptionByCode(code: string): boolean {
|
|
214
|
+
return this.collection.some((option) => option.code === code);
|
|
215
|
+
}
|
|
216
|
+
|
|
205
217
|
/**
|
|
206
218
|
* Get all options that have selected property true
|
|
207
219
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChoiceAttributeOptionCollection.js","names":["ResourceCollection","ChoiceAttributeOptionModel","ListHeaderModel","getBasePathModularUI","ChoiceAttributeOptionCollection","constructor","modelOptions","_defineProperty","_modelOptions","origin","contextPath","referenceDate","Date","toISOString","split","sortOptions","_sortOptions","collection","forEach","option","children","create","data","arguments","length","undefined","contributions","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","_context","_sortInstanceProperty","call","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","_context2","_context3","push","_mapInstanceProperty","_filterInstanceProperty","selected","key","toString","getOptionCount","code","foundOption","_findInstanceProperty","count","selectedValues","optionContributions","optionCode","addOption","optionType","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","optionValue","optionModel","add","deselectAll","_context4","newOption","clone","select","toggle","deselect","action","_context5","setReferenceDate","date","_context6","headers","_headers","child","mergeOptions","withOptions","addNotExistingOptions","removeNotExistingOptions","newCollection","withOption","mergeOption","some","opt","callbackfn","thisArg","optionIndex","collectionArray","result"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { getBasePathModularUI } from \"../../constants\";\n\nimport type { ChoiceAttributeOptionModelOptions } from \"./ChoiceAttributeOptionModel\";\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _modelOptions: ChoiceAttributeOptionModelOptions;\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n constructor(modelOptions?: ChoiceAttributeOptionModelOptions) {\n super();\n this._modelOptions = modelOptions || {\n origin: \"\",\n contextPath: getBasePathModularUI(),\n referenceDate: new Date().toISOString().split(\"T\")[0],\n };\n }\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n modelOptions?: ChoiceAttributeOptionModelOptions,\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection(modelOptions);\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key),\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(selectedValues, {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n optionType: contributions.optionType ?? \"generic\",\n });\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(selectedValues, {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n optionType: contributions.optionType ?? \"generic\",\n elementsContributions: contributions.children,\n });\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = [],\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionValue = value == null ? [] : [value.toString()];\n\n this.addBooleanOption(\"true\", \"Yes\", optionValue, contributions.options);\n this.addBooleanOption(\"false\", \"No\", optionValue, contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n this._modelOptions,\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false,\n removeNotExistingOptions: boolean = false,\n ) {\n const newCollection = [];\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code,\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n newCollection.push(option);\n } else if (!removeNotExistingOptions) {\n newCollection.push(option);\n }\n });\n\n if (addNotExistingOptions) {\n this.collection = [\n ...newCollection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code),\n ),\n ];\n } else {\n this.collection = newCollection;\n }\n }\n\n /**\n */\n some(\n callbackfn: (\n value: ChoiceAttributeOptionModel,\n index: number,\n array: Array<ChoiceAttributeOptionModel>,\n ) => any,\n thisArg?: any,\n ): boolean {\n return this.collection.some((option, optionIndex, collectionArray) => {\n const result = callbackfn(option, optionIndex, collectionArray);\n if (!result && option.children) {\n return option.children.some(callbackfn, thisArg);\n }\n return result;\n });\n }\n}\n\nexport default ChoiceAttributeOptionCollection;\n"],"mappings":";;;;;AACA,OAAOA,kBAAkB,MAAM,4BAA4B;AAC3D,OAAOC,0BAA0B,MAAM,8BAA8B;AACrE,OAAOC,eAAe,MAAM,yBAAyB;AAErD,SAASC,oBAAoB,QAAQ,iBAAiB;AAGtD;AACA;AACA,MAAMC,+BAA+B,SAASJ,kBAAkB,CAA6B;EAK3FK,WAAWA,CAACC,YAAgD,EAAE;IAC5D,KAAK,CAAC,CAAC;IAACC,eAAA;IAAAA,eAAA,mBAJyB,EAAE;IAAAA,eAAA,uBACb,KAAK;IAI3B,IAAI,CAACC,aAAa,GAAGF,YAAY,IAAI;MACnCG,MAAM,EAAE,EAAE;MACVC,WAAW,EAAEP,oBAAoB,CAAC,CAAC;MACnCQ,aAAa,EAAE,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;EACH;;EAEA;AACF;EACE,IAAIC,WAAWA,CAACA,WAAoB,EAAE;IACpC,IAAI,CAACC,YAAY,GAAGD,WAAW;IAE/B,IAAI,CAACE,UAAU,CAACC,OAAO,CAAEC,MAAM,IAAK;MAClC,IAAIA,MAAM,CAACC,QAAQ,EAAE;QACnBD,MAAM,CAACC,QAA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C/D,IAAI,CAACC,MAAM,IAAInF,MAAM,CAACC,QAAQ,EAAE;QAC9B,OAAOD,MAAM,CAACC,QAAQ,CAAC4E,IAAI,CAACE,UAAU,EAAEC,OAAO,CAAC;MAClD;MACA,OAAOG,MAAM;IACf,CAAC,CAAC;EACJ;AACF;AAEA,eAAelG,+BAA+B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ChoiceAttributeOptionCollection.js","names":["ResourceCollection","ChoiceAttributeOptionModel","ListHeaderModel","getBasePathModularUI","ChoiceAttributeOptionCollection","constructor","modelOptions","_defineProperty","_modelOptions","origin","contextPath","referenceDate","Date","toISOString","split","sortOptions","_sortOptions","collection","forEach","option","children","create","data","arguments","length","undefined","contributions","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","_context","_sortInstanceProperty","call","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","_context2","_context3","push","_mapInstanceProperty","_filterInstanceProperty","selected","key","toString","getOptionCount","code","foundOption","_findInstanceProperty","count","selectedValues","optionContributions","optionCode","addOption","optionType","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","optionValue","optionModel","add","getOptionByCode","_context4","hasOptionByCode","some","deselectAll","_context5","newOption","clone","select","toggle","deselect","action","_context6","setReferenceDate","date","_context7","headers","_headers","child","mergeOptions","withOptions","addNotExistingOptions","removeNotExistingOptions","newCollection","withOption","mergeOption","opt","callbackfn","thisArg","optionIndex","collectionArray","result"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { getBasePathModularUI } from \"../../constants\";\n\nimport type { ChoiceAttributeOptionModelOptions } from \"./ChoiceAttributeOptionModel\";\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _modelOptions: ChoiceAttributeOptionModelOptions;\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n constructor(modelOptions?: ChoiceAttributeOptionModelOptions) {\n super();\n this._modelOptions = modelOptions || {\n origin: \"\",\n contextPath: getBasePathModularUI(),\n referenceDate: new Date().toISOString().split(\"T\")[0],\n };\n }\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n modelOptions?: ChoiceAttributeOptionModelOptions,\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection(modelOptions);\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key),\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(selectedValues, {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n optionType: contributions.optionType ?? \"generic\",\n });\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(selectedValues, {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n optionType: contributions.optionType ?? \"generic\",\n elementsContributions: contributions.children,\n });\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = [],\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionValue = value == null ? [] : [value.toString()];\n\n this.addBooleanOption(\"true\", \"Yes\", optionValue, contributions.options);\n this.addBooleanOption(\"false\", \"No\", optionValue, contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n this._modelOptions,\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n */\n getOptionByCode(code: string): ChoiceAttributeOptionModel | void {\n return this.collection.find((option) => option.code === code);\n }\n\n /**\n */\n hasOptionByCode(code: string): boolean {\n return this.collection.some((option) => option.code === code);\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false,\n removeNotExistingOptions: boolean = false,\n ) {\n const newCollection = [];\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code,\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n newCollection.push(option);\n } else if (!removeNotExistingOptions) {\n newCollection.push(option);\n }\n });\n\n if (addNotExistingOptions) {\n this.collection = [\n ...newCollection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code),\n ),\n ];\n } else {\n this.collection = newCollection;\n }\n }\n\n /**\n */\n some(\n callbackfn: (\n value: ChoiceAttributeOptionModel,\n index: number,\n array: Array<ChoiceAttributeOptionModel>,\n ) => any,\n thisArg?: any,\n ): boolean {\n return this.collection.some((option, optionIndex, collectionArray) => {\n const result = callbackfn(option, optionIndex, collectionArray);\n if (!result && option.children) {\n return option.children.some(callbackfn, thisArg);\n }\n return result;\n });\n }\n}\n\nexport default ChoiceAttributeOptionCollection;\n"],"mappings":";;;;;AACA,OAAOA,kBAAkB,MAAM,4BAA4B;AAC3D,OAAOC,0BAA0B,MAAM,8BAA8B;AACrE,OAAOC,eAAe,MAAM,yBAAyB;AAErD,SAASC,oBAAoB,QAAQ,iBAAiB;AAGtD;AACA;AACA,MAAMC,+BAA+B,SAASJ,kBAAkB,CAA6B;EAK3FK,WAAWA,CAACC,YAAgD,EAAE;IAC5D,KAAK,CAAC,CAAC;IAACC,eAAA;IAAAA,eAAA,mBAJyB,EAAE;IAAAA,eAAA,uBACb,KAAK;IAI3B,IAAI,CAACC,aAAa,GAAGF,YAAY,IAAI;MACnCG,MAAM,EAAE,EAAE;MACVC,WAAW,EAAEP,oBAAoB,CAAC,CAAC;MACnCQ,aAAa,EAAE,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC;EACH;;EAEA;AACF;EACE,IAAIC,WAAWA,CAACA,WAAoB,EAAE;IACpC,IAAI,CAACC,YAAY,GAAGD,WAAW;IAE/B,IAAI,CAACE,UAAU,CAACC,OAAO,CAAEC,MAAM,IAAK;MAClC,IAAIA,MAAM,CAACC,QAAQ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AAC,IAAI,CAACF,UAAU,CAAC4D,IAAI,CAAEuB,GAAG,IAAKA,GAAG,CAAC5C,IAAI,KAAKrC,MAAM,CAACqC,IAAI,CACrE,CAAC,CACF;IACH,CAAC,MAAM;MACL,IAAI,CAACvC,UAAU,GAAGgF,aAAa;IACjC;EACF;;EAEA;AACF;EACEpB,IAAIA,CACFwB,UAIQ,EACRC,OAAa,EACJ;IACT,OAAO,IAAI,CAACrF,UAAU,CAAC4D,IAAI,CAAC,CAAC1D,MAAM,EAAEoF,WAAW,EAAEC,eAAe,KAAK;MACpE,MAAMC,MAAM,GAAGJ,UAAU,CAAClF,MAAM,EAAEoF,WAAW,EAAEC,eAAe,CAAC;MAC/D,IAAI,CAACC,MAAM,IAAItF,MAAM,CAACC,QAAQ,EAAE;QAC9B,OAAOD,MAAM,CAACC,QAAQ,CAACyD,IAAI,CAACwB,UAAU,EAAEC,OAAO,CAAC;MAClD;MACA,OAAOG,MAAM;IACf,CAAC,CAAC;EACJ;AACF;AAEA,eAAerG,+BAA+B","ignoreList":[]}
|
|
@@ -34,5 +34,9 @@ describe("conceptIndexModel", () => {
|
|
|
34
34
|
expect(firstItem.conceptTypeLink.href.toString()).toBe(
|
|
35
35
|
"/concepttypes/bundle-com.beinformed.fs.demo.metamodels/High%20level%20requirements.bixml/ArchitecturalSignificantRequirement",
|
|
36
36
|
);
|
|
37
|
+
|
|
38
|
+
const conceptIndexAttribute = conceptIndex.indexfilter?.attribute;
|
|
39
|
+
expect(conceptIndexAttribute.label).toBe("Index");
|
|
40
|
+
expect(conceptIndexAttribute.options.size).toBe(27);
|
|
37
41
|
});
|
|
38
42
|
});
|
|
@@ -11,17 +11,18 @@ export default class ConceptIndexFilterModel extends BaseFilterModel {
|
|
|
11
11
|
*/
|
|
12
12
|
constructor(data, contributions, modelOptions) {
|
|
13
13
|
super(data, contributions, modelOptions);
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (this.attribute instanceof ChoiceAttributeModel) {
|
|
15
|
+
const attribute = this.attribute;
|
|
16
|
+
if (attribute && data.options) {
|
|
17
|
+
var _context, _context2, _context3;
|
|
18
|
+
const selectedValues = _mapInstanceProperty(_context = _filterInstanceProperty(_context2 = data.options).call(_context2, option => option.selected)).call(_context, option => option.key);
|
|
19
|
+
_filterInstanceProperty(_context3 = data.options).call(_context3, option => !attribute.options.hasOptionByCode(option.key)).forEach(option => {
|
|
20
|
+
attribute.options.addOption(selectedValues, {
|
|
20
21
|
code: option.key,
|
|
21
22
|
label: option.key
|
|
22
23
|
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -18,19 +18,23 @@ export default class ConceptIndexFilterModel extends BaseFilterModel {
|
|
|
18
18
|
) {
|
|
19
19
|
super(data, contributions, modelOptions);
|
|
20
20
|
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
.filter((option) => option.selected)
|
|
24
|
-
.map((option) => option.key);
|
|
21
|
+
if (this.attribute instanceof ChoiceAttributeModel) {
|
|
22
|
+
const attribute: ChoiceAttributeModel = this.attribute;
|
|
25
23
|
|
|
26
|
-
data.options
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
if (attribute && data.options) {
|
|
25
|
+
const selectedValues = data.options
|
|
26
|
+
.filter((option) => option.selected)
|
|
27
|
+
.map((option) => option.key);
|
|
28
|
+
|
|
29
|
+
data.options
|
|
30
|
+
.filter((option) => !attribute.options.hasOptionByCode(option.key))
|
|
31
|
+
.forEach((option) => {
|
|
32
|
+
attribute.options.addOption(selectedValues, {
|
|
33
|
+
code: option.key,
|
|
34
|
+
label: option.key,
|
|
35
|
+
});
|
|
31
36
|
});
|
|
32
|
-
|
|
33
|
-
});
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConceptIndexFilterModel.js","names":["BaseFilterModel","ChoiceAttributeModel","ConceptIndexFilterModel","constructor","data","contributions","modelOptions","options","_context","_context2","selectedValues","_mapInstanceProperty","_filterInstanceProperty","call","option","selected","key","
|
|
1
|
+
{"version":3,"file":"ConceptIndexFilterModel.js","names":["BaseFilterModel","ChoiceAttributeModel","ConceptIndexFilterModel","constructor","data","contributions","modelOptions","attribute","options","_context","_context2","_context3","selectedValues","_mapInstanceProperty","_filterInstanceProperty","call","option","selected","key","hasOptionByCode","forEach","addOption","code","label"],"sources":["../../../src/models/filters/ConceptIndexFilterModel.js"],"sourcesContent":["// @flow\nimport BaseFilterModel from \"../filters/BaseFilterModel\";\nimport ChoiceAttributeModel from \"../attributes/ChoiceAttributeModel\";\n\nimport type { ModelOptions } from \"../types\";\n\n/**\n * The concept index model is a special filter used to index all first concept label letters in de modelcatalog.\n */\nexport default class ConceptIndexFilterModel extends BaseFilterModel {\n /**\n * Construct a filter\n */\n constructor(\n data: Object,\n contributions: Object,\n modelOptions?: ModelOptions,\n ) {\n super(data, contributions, modelOptions);\n\n if (this.attribute instanceof ChoiceAttributeModel) {\n const attribute: ChoiceAttributeModel = this.attribute;\n\n if (attribute && data.options) {\n const selectedValues = data.options\n .filter((option) => option.selected)\n .map((option) => option.key);\n\n data.options\n .filter((option) => !attribute.options.hasOptionByCode(option.key))\n .forEach((option) => {\n attribute.options.addOption(selectedValues, {\n code: option.key,\n label: option.key,\n });\n });\n }\n }\n }\n}\n"],"mappings":";;AACA,OAAOA,eAAe,MAAM,4BAA4B;AACxD,OAAOC,oBAAoB,MAAM,oCAAoC;AAIrE;AACA;AACA;AACA,eAAe,MAAMC,uBAAuB,SAASF,eAAe,CAAC;EACnE;AACF;AACA;EACEG,WAAWA,CACTC,IAAY,EACZC,aAAqB,EACrBC,YAA2B,EAC3B;IACA,KAAK,CAACF,IAAI,EAAEC,aAAa,EAAEC,YAAY,CAAC;IAExC,IAAI,IAAI,CAACC,SAAS,YAAYN,oBAAoB,EAAE;MAClD,MAAMM,SAA+B,GAAG,IAAI,CAACA,SAAS;MAEtD,IAAIA,SAAS,IAAIH,IAAI,CAACI,OAAO,EAAE;QAAA,IAAAC,QAAA,EAAAC,SAAA,EAAAC,SAAA;QAC7B,MAAMC,cAAc,GAAGC,oBAAA,CAAAJ,QAAA,GAAAK,uBAAA,CAAAJ,SAAA,GAAAN,IAAI,CAACI,OAAO,EAAAO,IAAA,CAAAL,SAAA,EACxBM,MAAM,IAAKA,MAAM,CAACC,QAAQ,CAAC,EAAAF,IAAA,CAAAN,QAAA,EAC9BO,MAAM,IAAKA,MAAM,CAACE,GAAG,CAAC;QAE9BJ,uBAAA,CAAAH,SAAA,GAAAP,IAAI,CAACI,OAAO,EAAAO,IAAA,CAAAJ,SAAA,EACDK,MAAM,IAAK,CAACT,SAAS,CAACC,OAAO,CAACW,eAAe,CAACH,MAAM,CAACE,GAAG,CAAC,CAAC,CAClEE,OAAO,CAAEJ,MAAM,IAAK;UACnBT,SAAS,CAACC,OAAO,CAACa,SAAS,CAACT,cAAc,EAAE;YAC1CU,IAAI,EAAEN,MAAM,CAACE,GAAG;YAChBK,KAAK,EAAEP,MAAM,CAACE;UAChB,CAAC,CAAC;QACJ,CAAC,CAAC;MACN;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
2
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
3
|
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
4
|
-
import { getBasePathModularUI, getUploadPath, HTTP_METHODS } from "../constants";
|
|
4
|
+
import { getBasePathModularUI, getSetting, getUploadPath, HTTP_METHODS } from "../constants";
|
|
5
5
|
import xhr from "../utils/fetch/xhr";
|
|
6
6
|
import ErrorModel from "../models/error/ErrorModel";
|
|
7
|
+
import { ErrorResponse } from "../models";
|
|
7
8
|
/**
|
|
8
9
|
* Upload a file to the upload file service of Be Informed
|
|
9
10
|
*/
|
|
@@ -50,7 +51,7 @@ class UploadRequest {
|
|
|
50
51
|
*/
|
|
51
52
|
uploadFile(file) {
|
|
52
53
|
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
53
|
-
if (this.exceedsMaxFileSize(file)) {
|
|
54
|
+
if (getSetting("USE_CLIENTSIDE_VALIDATION") && this.exceedsMaxFileSize(file)) {
|
|
54
55
|
this._progressHandler(file, {
|
|
55
56
|
error: "errorExceedsMaxFileSize"
|
|
56
57
|
});
|
|
@@ -58,7 +59,7 @@ class UploadRequest {
|
|
|
58
59
|
"max-filesize": maxFileSize
|
|
59
60
|
}, true));
|
|
60
61
|
}
|
|
61
|
-
if (this.isNotAllowedFileType(file)) {
|
|
62
|
+
if (getSetting("USE_CLIENTSIDE_VALIDATION") && this.isNotAllowedFileType(file)) {
|
|
62
63
|
this._progressHandler(file, {
|
|
63
64
|
error: "errorExtensionNotAllowed"
|
|
64
65
|
});
|
|
@@ -89,7 +90,7 @@ class UploadRequest {
|
|
|
89
90
|
token: response.token
|
|
90
91
|
});
|
|
91
92
|
return response;
|
|
92
|
-
});
|
|
93
|
+
}).catch(e => _Promise.reject(new ErrorResponse(e)));
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
export default UploadRequest;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import {
|
|
3
3
|
getBasePathModularUI,
|
|
4
|
+
getSetting,
|
|
4
5
|
getUploadPath,
|
|
5
6
|
HTTP_METHODS,
|
|
6
7
|
} from "../constants";
|
|
@@ -12,6 +13,7 @@ import type {
|
|
|
12
13
|
FiletypeConstraintsType,
|
|
13
14
|
} from "../models";
|
|
14
15
|
import ErrorModel from "../models/error/ErrorModel";
|
|
16
|
+
import { ErrorResponse } from "../models";
|
|
15
17
|
|
|
16
18
|
type ProgressHandler = (file: File, uploadInfo: Object) => void;
|
|
17
19
|
|
|
@@ -86,7 +88,10 @@ class UploadRequest {
|
|
|
86
88
|
uploadFile(file: File): Promise<UploadResponse> {
|
|
87
89
|
const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;
|
|
88
90
|
|
|
89
|
-
if (
|
|
91
|
+
if (
|
|
92
|
+
getSetting("USE_CLIENTSIDE_VALIDATION") &&
|
|
93
|
+
this.exceedsMaxFileSize(file)
|
|
94
|
+
) {
|
|
90
95
|
this._progressHandler(file, { error: "errorExceedsMaxFileSize" });
|
|
91
96
|
return Promise.reject(
|
|
92
97
|
new ErrorModel(
|
|
@@ -100,7 +105,10 @@ class UploadRequest {
|
|
|
100
105
|
);
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
if (
|
|
108
|
+
if (
|
|
109
|
+
getSetting("USE_CLIENTSIDE_VALIDATION") &&
|
|
110
|
+
this.isNotAllowedFileType(file)
|
|
111
|
+
) {
|
|
104
112
|
this._progressHandler(file, { error: "errorExtensionNotAllowed" });
|
|
105
113
|
return Promise.reject(
|
|
106
114
|
new ErrorModel(
|
|
@@ -131,10 +139,12 @@ class UploadRequest {
|
|
|
131
139
|
}
|
|
132
140
|
},
|
|
133
141
|
data: file,
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
})
|
|
143
|
+
.then((response) => {
|
|
144
|
+
this._progressHandler(file, { progress: 100, token: response.token });
|
|
145
|
+
return response;
|
|
146
|
+
})
|
|
147
|
+
.catch((e) => Promise.reject(new ErrorResponse(e)));
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UploadRequest.js","names":["getBasePathModularUI","getUploadPath","HTTP_METHODS","xhr","ErrorModel","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includesInstanceProperty","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","error","_Promise","reject","extension","join","url","method","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (this.exceedsMaxFileSize(file)) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (this.isNotAllowedFileType(file)) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n }).then((response) => {\n
|
|
1
|
+
{"version":3,"file":"UploadRequest.js","names":["getBasePathModularUI","getSetting","getUploadPath","HTTP_METHODS","xhr","ErrorModel","ErrorResponse","UploadRequest","constructor","uploadConstraints","progressHandler","options","_defineProperty","_uploadConstraints","_progressHandler","_origin","origin","_contextPath","contextPath","getFileExtension","file","name","split","pop","toLowerCase","isNotAllowedFileType","allowedFileTypes","fileTypes","length","fileExtension","some","fileType","_context","_includesInstanceProperty","extensions","call","exceedsMaxFileSize","maxFileSize","fileSize","size","uploadFile","error","_Promise","reject","extension","join","url","method","POST","headers","type","encodeURIComponent","toString","onProgress","e","lengthComputable","progress","Math","ceil","loaded","total","data","then","response","token","catch"],"sources":["../../src/modularui/UploadRequest.js"],"sourcesContent":["// @flow\nimport {\n getBasePathModularUI,\n getSetting,\n getUploadPath,\n HTTP_METHODS,\n} from \"../constants\";\n\nimport xhr from \"../utils/fetch/xhr\";\n\nimport type {\n FilesizeConstraintsType,\n FiletypeConstraintsType,\n} from \"../models\";\nimport ErrorModel from \"../models/error/ErrorModel\";\nimport { ErrorResponse } from \"../models\";\n\ntype ProgressHandler = (file: File, uploadInfo: Object) => void;\n\ntype UploadRequestOptions = {\n origin?: string,\n contextPath?: string,\n};\n\ntype UploadResponse = {\n token: string,\n};\n\n/**\n * Upload a file to the upload file service of Be Informed\n */\nclass UploadRequest {\n _uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n };\n _progressHandler: ProgressHandler;\n _origin: string = \"\";\n _contextPath: string = getBasePathModularUI();\n\n constructor(\n uploadConstraints: {\n fileTypes: FiletypeConstraintsType,\n maxFileSize: FilesizeConstraintsType,\n acceptedFiles: Array<string>,\n },\n progressHandler: ProgressHandler,\n options?: UploadRequestOptions,\n ) {\n this._uploadConstraints = uploadConstraints;\n this._progressHandler = progressHandler;\n this._origin = options?.origin || \"\";\n this._contextPath = options?.contextPath || getBasePathModularUI();\n }\n\n /**\n */\n getFileExtension(file: File): string {\n return file.name.split(\".\").pop().toLowerCase();\n }\n\n /**\n */\n isNotAllowedFileType(file: File): boolean {\n const allowedFileTypes = this._uploadConstraints.fileTypes;\n\n if (allowedFileTypes.length > 0) {\n const fileExtension = this.getFileExtension(file);\n\n return !allowedFileTypes.some((fileType) =>\n fileType.extensions.includes(fileExtension),\n );\n }\n\n return false;\n }\n\n /**\n */\n exceedsMaxFileSize(file: File): boolean {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n return maxFileSize > -1 && file.size > maxFileSize;\n }\n\n /**\n */\n uploadFile(file: File): Promise<UploadResponse> {\n const maxFileSize = this._uploadConstraints?.maxFileSize?.fileSize ?? -1;\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.exceedsMaxFileSize(file)\n ) {\n this._progressHandler(file, { error: \"errorExceedsMaxFileSize\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.MaxFileSizeExceeded\",\n \"Maximum file upload size is ${max-filesize}\",\n {\n \"max-filesize\": maxFileSize,\n },\n true,\n ),\n );\n }\n\n if (\n getSetting(\"USE_CLIENTSIDE_VALIDATION\") &&\n this.isNotAllowedFileType(file)\n ) {\n this._progressHandler(file, { error: \"errorExtensionNotAllowed\" });\n return Promise.reject(\n new ErrorModel(\n \"Constraint.File.InvalidExtension\",\n \"Allowed extensions are: ${extensions}\",\n {\n extension: this.getFileExtension(file),\n extensions: this._uploadConstraints.fileTypes.join(\", \"),\n },\n true,\n ),\n );\n }\n\n return xhr({\n url: getUploadPath(this._contextPath, this._origin),\n method: HTTP_METHODS.POST,\n headers: {\n \"Content-Type\": file.type,\n \"x-filename\": encodeURIComponent(file.name),\n \"x-filesize\": file.size.toString(),\n },\n onProgress: (e: ProgressEvent) => {\n if (this._progressHandler && e.lengthComputable) {\n this._progressHandler(file, {\n progress: Math.ceil((e.loaded / e.total) * 100),\n });\n }\n },\n data: file,\n })\n .then((response) => {\n this._progressHandler(file, { progress: 100, token: response.token });\n return response;\n })\n .catch((e) => Promise.reject(new ErrorResponse(e)));\n }\n}\n\nexport default UploadRequest;\n"],"mappings":";;;AACA,SACEA,oBAAoB,EACpBC,UAAU,EACVC,aAAa,EACbC,YAAY,QACP,cAAc;AAErB,OAAOC,GAAG,MAAM,oBAAoB;AAMpC,OAAOC,UAAU,MAAM,4BAA4B;AACnD,SAASC,aAAa,QAAQ,WAAW;AAazC;AACA;AACA;AACA,MAAMC,aAAa,CAAC;EAUlBC,WAAWA,CACTC,iBAIC,EACDC,eAAgC,EAChCC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AAI,IAAI,CAACxC,gBAAgB,IAAIwC,CAAC,CAACC,gBAAgB,EAAE;UAC/C,IAAI,CAACzC,gBAAgB,CAACM,IAAI,EAAE;YAC1BoC,QAAQ,EAAEC,IAAI,CAACC,IAAI,CAAEJ,CAAC,CAACK,MAAM,GAAGL,CAAC,CAACM,KAAK,GAAI,GAAG;UAChD,CAAC,CAAC;QACJ;MACF,CAAC;MACDC,IAAI,EAAEzC;IACR,CAAC,CAAC,CACC0C,IAAI,CAAEC,QAAQ,IAAK;MAClB,IAAI,CAACjD,gBAAgB,CAACM,IAAI,EAAE;QAAEoC,QAAQ,EAAE,GAAG;QAAEQ,KAAK,EAAED,QAAQ,CAACC;MAAM,CAAC,CAAC;MACrE,OAAOD,QAAQ;IACjB,CAAC,CAAC,CACDE,KAAK,CAAEX,CAAC,IAAKZ,QAAA,CAAQC,MAAM,CAAC,IAAIrC,aAAa,CAACgD,CAAC,CAAC,CAAC,CAAC;EACvD;AACF;AAEA,eAAe/C,aAAa","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ export function useConceptIndex(href: string | Href, key?: string, options?: Use
|
|
|
10
10
|
export function useConceptDetail(concept: string | Href, key?: string, options?: UseModularUIBasicOptions<ConceptDetailModel | BusinessScenarioModel>): (ConceptDetailModel | (BusinessScenarioModel | null)) | null;
|
|
11
11
|
export function useContentIndex(href: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentIndexModel>): ContentIndexModel | null;
|
|
12
12
|
export function useContentTOC(content: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentTOCModel>): ContentTOCModel | null;
|
|
13
|
-
export function useContent(
|
|
13
|
+
export function useContent(content: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentModel>): (ContentModel | (ContentTOCModel | null)) | null;
|
|
14
14
|
export function useContentType(contentType: string | Href, key?: string, options?: UseModularUIBasicOptions<ContentTypeModel>): ContentTypeModel | null;
|
|
15
15
|
export function useConceptSearch(filters: SearchFilter, key?: string, options?: UseModularUIBasicOptions<ConceptIndexModel>): ConceptIndexModel | null;
|
|
16
16
|
export function useContentSearch(filters: SearchFilter, key?: string, options?: UseModularUIBasicOptions<ContentIndexModel>): ContentIndexModel | null;
|