ember-ebau-gwr 4.0.7 → 5.0.2

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.
Files changed (161) hide show
  1. package/CHANGELOG.md +312 -299
  2. package/README.md +25 -8
  3. package/addon/components/building-preview.hbs +53 -0
  4. package/addon/components/housing-stat-link.hbs +8 -0
  5. package/addon/components/import-modal/building-data.hbs +1 -55
  6. package/addon/components/import-modal/dwelling-data.hbs +3 -3
  7. package/addon/components/import-modal/entrance-data.hbs +1 -1
  8. package/addon/components/import-modal.hbs +1 -4
  9. package/addon/components/link-building-modal.hbs +38 -24
  10. package/addon/components/link-building-modal.js +13 -5
  11. package/addon/components/link-street.hbs +33 -31
  12. package/addon/components/linked-models.hbs +13 -6
  13. package/addon/components/linked-projects.hbs +8 -6
  14. package/addon/components/linked-projects.js +13 -0
  15. package/addon/components/loading.hbs +3 -0
  16. package/addon/components/login-modal.hbs +86 -68
  17. package/addon/components/model-errors/error-indicator.hbs +1 -2
  18. package/addon/components/model-errors/header.hbs +6 -2
  19. package/addon/components/model-errors/list.hbs +13 -4
  20. package/addon/components/model-errors/skeleton-errors.hbs +14 -0
  21. package/addon/components/model-errors/skeleton.hbs +1 -16
  22. package/addon/components/model-errors.hbs +14 -16
  23. package/addon/components/model-form/date.hbs +10 -6
  24. package/addon/components/model-form/diff.hbs +8 -8
  25. package/addon/components/model-form/field.hbs +3 -2
  26. package/addon/components/model-form/field.js +7 -5
  27. package/addon/components/model-form/header/actions.hbs +25 -22
  28. package/addon/components/model-form/header/actions.js +6 -3
  29. package/addon/components/model-form/header/errors.hbs +16 -16
  30. package/addon/components/model-form/header/status-selector/submit-parameters.hbs +2 -1
  31. package/addon/components/model-form/header/status-selector.hbs +15 -3
  32. package/addon/components/model-form/header/status.hbs +2 -1
  33. package/addon/components/model-form/header.hbs +6 -5
  34. package/addon/components/model-form/step.hbs +5 -5
  35. package/addon/components/model-form/submit.hbs +1 -0
  36. package/addon/components/model-form.hbs +110 -77
  37. package/addon/components/model-form.js +38 -2
  38. package/addon/components/model-inview.hbs +2 -7
  39. package/addon/components/project-landing-page.hbs +26 -0
  40. package/addon/components/project-nav.hbs +65 -0
  41. package/addon/components/project-nav.js +27 -0
  42. package/addon/components/quarterly-closure/card-status.hbs +11 -0
  43. package/addon/components/quarterly-closure/card-status.js +36 -0
  44. package/addon/components/quarterly-closure/close-survey-button.hbs +10 -0
  45. package/addon/components/quarterly-closure/close-survey-button.js +46 -0
  46. package/addon/components/quarterly-closure/disabled-form-info.hbs +4 -0
  47. package/addon/components/quarterly-closure/error-list/project-errors.hbs +22 -0
  48. package/addon/components/quarterly-closure/error-list/project-errors.js +41 -0
  49. package/addon/components/quarterly-closure/error-list/survey-department-errors.hbs +22 -0
  50. package/addon/components/quarterly-closure/error-list/survey-department-errors.js +28 -0
  51. package/addon/components/quarterly-closure/error-list.hbs +4 -0
  52. package/addon/components/quarterly-closure/status.hbs +8 -0
  53. package/addon/components/quarterly-closure/status.js +6 -0
  54. package/addon/components/quarterly-closure/title.hbs +15 -0
  55. package/addon/components/quarterly-closure/title.js +11 -0
  56. package/addon/components/quarterly-closure.hbs +9 -0
  57. package/addon/components/quarterly-closure.js +6 -0
  58. package/addon/components/search/filters.hbs +128 -106
  59. package/addon/components/search/filters.js +13 -59
  60. package/addon/components/search/result-table/head/header.hbs +1 -1
  61. package/addon/components/search/result-table/head.hbs +1 -1
  62. package/addon/components/search/result-table/load-more.hbs +5 -0
  63. package/addon/components/search/result-table/row/field.hbs +1 -1
  64. package/addon/components/search/result-table/row.hbs +12 -13
  65. package/addon/components/search/result-table.hbs +3 -2
  66. package/addon/components/search.hbs +29 -0
  67. package/addon/components/search.js +96 -0
  68. package/addon/components/soon-available.hbs +7 -0
  69. package/addon/components/sub-nav.hbs +5 -8
  70. package/addon/components/title-card.hbs +28 -0
  71. package/addon/components/validated-form-error.hbs +4 -0
  72. package/addon/components/validated-form-error.js +14 -0
  73. package/addon/controllers/building/edit/dwelling/edit.js +2 -3
  74. package/addon/controllers/building/edit/entrance/edit/index.js +2 -3
  75. package/addon/controllers/building/edit/entrance/edit/link-street.js +4 -1
  76. package/addon/controllers/building/edit/form.js +57 -39
  77. package/addon/controllers/import.js +8 -64
  78. package/addon/controllers/project/form.js +3 -4
  79. package/addon/controllers/project.js +22 -44
  80. package/addon/controllers/search-building.js +39 -14
  81. package/addon/controllers/search-project.js +24 -19
  82. package/addon/helpers/current-quarter.js +8 -0
  83. package/addon/helpers/current-route-is-not.js +7 -0
  84. package/addon/helpers/current-route-is.js +15 -0
  85. package/addon/helpers/is-set.js +9 -0
  86. package/addon/helpers/is-unset.js +4 -4
  87. package/addon/helpers/show-model-field.js +4 -4
  88. package/addon/models/check-construction-project-response.js +20 -0
  89. package/addon/models/check-survey-department-response.js +20 -0
  90. package/addon/models/quarterly-closure-status.js +52 -0
  91. package/addon/modifiers/in-viewport.js +14 -0
  92. package/addon/modifiers/inverse-background.js +21 -0
  93. package/addon/resources/import.js +69 -0
  94. package/addon/routes/building/edit.js +1 -1
  95. package/addon/routes/building/new.js +1 -1
  96. package/addon/routes/building.js +7 -2
  97. package/addon/routes/global-landing-page.js +9 -0
  98. package/addon/routes/project/errors.js +1 -1
  99. package/addon/routes/project/form.js +1 -1
  100. package/addon/routes/project/new.js +1 -1
  101. package/addon/routes/project.js +1 -1
  102. package/addon/routes/quarterly-closure.js +3 -0
  103. package/addon/routes/search-building.js +7 -2
  104. package/addon/routes.js +7 -3
  105. package/addon/services/auth-fetch.js +6 -7
  106. package/addon/services/construction-project.js +10 -0
  107. package/addon/services/gwr.js +19 -7
  108. package/addon/services/quarterly-closure.js +147 -0
  109. package/addon/templates/building/edit/dwelling/edit.hbs +22 -19
  110. package/addon/templates/building/edit/dwelling/new.hbs +1 -1
  111. package/addon/templates/building/edit/dwelling.hbs +1 -1
  112. package/addon/templates/building/edit/dwellings.hbs +3 -4
  113. package/addon/templates/building/edit/entrance/edit/index.hbs +32 -18
  114. package/addon/templates/building/edit/entrance/edit/link-street.hbs +79 -75
  115. package/addon/templates/building/edit/entrance/edit.hbs +1 -1
  116. package/addon/templates/building/edit/entrance/new.hbs +1 -1
  117. package/addon/templates/building/edit/entrance.hbs +6 -5
  118. package/addon/templates/building/edit/entrances.hbs +4 -6
  119. package/addon/templates/building/edit/form.hbs +127 -112
  120. package/addon/templates/building/edit/index.hbs +1 -1
  121. package/addon/templates/building/edit.hbs +33 -23
  122. package/addon/templates/building.hbs +1 -1
  123. package/addon/templates/global-landing-page.hbs +34 -0
  124. package/addon/templates/project/errors.hbs +116 -109
  125. package/addon/templates/project/form.hbs +96 -63
  126. package/addon/templates/project/index.hbs +0 -1
  127. package/addon/templates/project/linked-buildings.hbs +7 -10
  128. package/addon/templates/project.hbs +12 -73
  129. package/addon/templates/quarterly-closure.hbs +1 -0
  130. package/addon/templates/search-building.hbs +202 -134
  131. package/addon/templates/search-project.hbs +98 -85
  132. package/addon/validations/building-work.js +106 -97
  133. package/addon/validations/extended-search-fields.js +27 -0
  134. package/addon/validations/realestate-identification.js +1 -0
  135. package/addon/xml/helpers.js +3 -0
  136. package/addon/xml/templates/building.js +1 -1
  137. package/addon/xml/templates/construction-project.js +1 -1
  138. package/app/styles/ember-ebau-gwr.scss +19 -0
  139. package/config/environment.js +4 -0
  140. package/config/icons.js +15 -0
  141. package/package.json +19 -15
  142. package/translations/de.yaml +29 -26
  143. package/translations/fr.yaml +11 -19
  144. package/translations/quarterly-closure/de.yaml +59 -0
  145. package/translations/validation-errors/de.yaml +37 -0
  146. package/addon/components/landing-page.hbs +0 -24
  147. package/addon/components/project-form/checkbox.hbs +0 -11
  148. package/addon/components/project-form/checkbox.js +0 -9
  149. package/addon/components/project-form/date.hbs +0 -10
  150. package/addon/components/project-form/diff.hbs +0 -43
  151. package/addon/components/project-form/diff.js +0 -18
  152. package/addon/components/project-form/field.hbs +0 -32
  153. package/addon/components/project-form/field.js +0 -59
  154. package/addon/components/project-form/input.hbs +0 -7
  155. package/addon/components/project-form/label.hbs +0 -17
  156. package/addon/components/project-form/select.hbs +0 -17
  157. package/addon/components/project-form/textarea.hbs +0 -7
  158. package/addon/components/project-form.hbs +0 -19
  159. package/addon/components/project-form.js +0 -14
  160. package/addon/components/sub-nav.js +0 -18
  161. package/addon/services/import-state.js +0 -10
@@ -0,0 +1,9 @@
1
+ import { helper } from "@ember/component/helper";
2
+
3
+ import { isUnset } from "./is-unset";
4
+
5
+ export function isSet(...args) {
6
+ return !isUnset(...args);
7
+ }
8
+
9
+ export default helper(([value]) => isSet(value));
@@ -1,7 +1,7 @@
1
1
  import { helper } from "@ember/component/helper";
2
2
 
3
- const isUnset = function isUnset([value]) {
4
- return value === null || value === undefined || isNaN(value);
5
- };
3
+ export function isUnset(value) {
4
+ return value === null || value === undefined;
5
+ }
6
6
 
7
- export default helper(isUnset);
7
+ export default helper(([value]) => isUnset(value));
@@ -1,12 +1,12 @@
1
1
  import { helper } from "@ember/component/helper";
2
2
  import { get } from "@ember/object";
3
3
 
4
- function showModelField([field, changeset, importData]) {
4
+ function showModelField([field, maybeChangeset, importedData]) {
5
5
  const isSet = (value) => value !== undefined && value !== null;
6
6
 
7
- return changeset
8
- ? isSet(changeset.get(field)) ||
9
- (importData && isSet(get(importData.data, field)))
7
+ return maybeChangeset
8
+ ? isSet(maybeChangeset.get?.(field) || maybeChangeset[field]) ||
9
+ (importedData && isSet(get(importedData.data, field)))
10
10
  : false;
11
11
  }
12
12
 
@@ -0,0 +1,20 @@
1
+ import { tracked } from "@glimmer/tracking";
2
+
3
+ import ErrorList from "./error-list";
4
+ import XMLModel from "./xml-model";
5
+
6
+ export default class CheckConstructionProjectResponse extends XMLModel {
7
+ @tracked EPROID;
8
+ @tracked errorList;
9
+
10
+ constructor(xmlOrObject, root = "checkConstructionProjectResponse") {
11
+ super(xmlOrObject);
12
+ this.setFieldsFromXML({
13
+ root,
14
+ fields: {
15
+ EPROID: Number,
16
+ errorList: [ErrorList],
17
+ },
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import { tracked } from "@glimmer/tracking";
2
+
3
+ import ErrorList from "./error-list";
4
+ import XMLModel from "./xml-model";
5
+
6
+ export default class CheckSurveyDepartmentResponse extends XMLModel {
7
+ @tracked constructionSurveyDeptNumber;
8
+ @tracked errorList;
9
+
10
+ constructor(xmlOrObject, root = "checkQuaterlySurveyDeptResponse") {
11
+ super(xmlOrObject);
12
+ this.setFieldsFromXML({
13
+ root,
14
+ fields: {
15
+ constructionSurveyDeptNumber: Number,
16
+ errorList: [ErrorList],
17
+ },
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,52 @@
1
+ import { tracked } from "@glimmer/tracking";
2
+
3
+ import XMLModel from "./xml-model";
4
+
5
+ export default class QuarterlyClosureStatus extends XMLModel {
6
+ @tracked constructionSurveyDeptNumber;
7
+ @tracked surveyStatus;
8
+
9
+ constructor(xmlOrObject, root = "quarterlySurveyResponse") {
10
+ super(xmlOrObject);
11
+ this.setFieldsFromXML({
12
+ root,
13
+ fields: {
14
+ constructionSurveyDeptNumber: Number,
15
+ surveyStatus: Number,
16
+ },
17
+ });
18
+
19
+ this.setFieldsFromXML({
20
+ root: "errors",
21
+ fields: {
22
+ error: [String],
23
+ },
24
+ });
25
+ }
26
+ }
27
+ export const [REQUEST_PENDING, WAITING, PROCESSING, ERROR, CLOSED] = [
28
+ "requestPending",
29
+ "waiting",
30
+ "processing",
31
+ "error",
32
+ "closed",
33
+ ];
34
+
35
+ export const STATUS_TYPES = {
36
+ 610: PROCESSING, // Datenerhebung initialisiert
37
+ 620: WAITING, // Erhebungsstelle wird aufgefordert Abschluss zu machen
38
+ 630: ERROR, // Abschluss durch die Erhebungsstelle mit Fehler
39
+ 640: ERROR, // Abschluss durch die Erhebungsstelle mit Fehler
40
+ 650: ERROR, // Kontrolle durch Kanton mit Fehler
41
+ 651: ERROR, // Abschluss durch die Erhebungsstelle mit Fehler
42
+ 660: PROCESSING, // Abschluss der EHS bereit zur Kontrolle für den Kanton
43
+ 661: PROCESSING, // Erneuter Abschluss EHS bereit zur Kontrolle für den Kanton
44
+ 662: PROCESSING, // Abschluss der EHS bereit zur Kontrolle für das BFS
45
+ 663: ERROR, // Kontrolle durch BFS mit Fehler
46
+ 665: ERROR, // Abschluss durch die Erhebungsstelle mit Fehler
47
+ 667: PROCESSING, // Erneuter Abschluss EHS bereit zur Kontrolle für das BFS
48
+ 670: PROCESSING, // Kontrollliste erstellt
49
+ 680: PROCESSING, // Abschluss durch das BFS
50
+ 690: CLOSED, // Daten der Erhebung kopiert für Snapshots BAU und CASA
51
+ 691: CLOSED, // Erzwungener Abschl. BFS
52
+ };
@@ -0,0 +1,14 @@
1
+ import { modifier } from "ember-modifier";
2
+
3
+ export default modifier(function inViewport(
4
+ element,
5
+ _,
6
+ { onEnter = () => {}, onExit = () => {}, root = "#scroll-container" }
7
+ ) {
8
+ const intersectionObserver = new IntersectionObserver(
9
+ ([{ isIntersecting }]) => (isIntersecting ? onEnter() : onExit()),
10
+ { root: root instanceof Element ? root : document.getElementById(root) }
11
+ );
12
+ intersectionObserver.observe(element);
13
+ return () => intersectionObserver.disconnect();
14
+ });
@@ -0,0 +1,21 @@
1
+ import { modifier } from "ember-modifier";
2
+
3
+ // This modifiers allows to inverse a elment's color
4
+ // if the backgroundColor of the element and its parent match.
5
+ //
6
+ // This way we can for instance inverse the icon-button on striped
7
+ // tables.
8
+ // @inverse => Color
9
+ // @compareTo => CSSSelector
10
+ export default modifier(function inverseBackground(
11
+ element,
12
+ _,
13
+ { inverse, compareTo }
14
+ ) {
15
+ const style = window.getComputedStyle(element);
16
+ const parentElement = element.closest(compareTo);
17
+ const parentStyle = window.getComputedStyle(parentElement);
18
+ if (style.backgroundColor === parentStyle.backgroundColor) {
19
+ element.style.backgroundColor = inverse;
20
+ }
21
+ });
@@ -0,0 +1,69 @@
1
+ import { assert } from "@ember/debug";
2
+ import { inject as service } from "@ember/service";
3
+ import { tracked } from "@glimmer/tracking";
4
+ import { task, lastValue } from "ember-concurrency";
5
+ import { Resource } from "ember-resources";
6
+
7
+ const IMPORT_MAP = {
8
+ project: "fetchProject",
9
+ building: "fetchBuildings",
10
+ dwelling: "fetchDwellings",
11
+ buildingEntrance: "fetchEntrances",
12
+ };
13
+
14
+ export const NO_DATA_ERROR = Symbol("no-data");
15
+
16
+ export default class ImportResource extends Resource {
17
+ @service dataImport;
18
+ @service router;
19
+
20
+ @tracked error = null;
21
+
22
+ get isLoading() {
23
+ return this.fetchCalumaData.isRunning;
24
+ }
25
+
26
+ get hasError() {
27
+ return Boolean(this.error);
28
+ }
29
+
30
+ modify(_positional, named) {
31
+ this.fetchCalumaData.perform(named);
32
+ }
33
+
34
+ @lastValue("fetchCalumaData") value;
35
+ @task
36
+ *fetchCalumaData({ instanceId, showImport, importModelName }) {
37
+ this.error = null;
38
+
39
+ if (instanceId && showImport) {
40
+ assert(
41
+ "Must set `importModelName` to a string.",
42
+ typeof importModelName === "string"
43
+ );
44
+ assert(
45
+ "Must set `instanceId`.",
46
+ instanceId !== null && instanceId !== undefined
47
+ );
48
+ try {
49
+ const data = yield this.dataImport[IMPORT_MAP[importModelName]](
50
+ instanceId
51
+ );
52
+ if (Object.keys(data).length === 0 || data.length === 0) {
53
+ this.router.externalRouter.transitionTo({
54
+ queryParams: { import: false },
55
+ });
56
+ this.error = NO_DATA_ERROR;
57
+ } else {
58
+ return data?.length === 1 ? data[0] : data;
59
+ }
60
+ } catch (error) {
61
+ console.error(error);
62
+ this.error = error;
63
+ return null;
64
+ }
65
+ } else {
66
+ return null;
67
+ }
68
+ }
69
+ }
@@ -5,7 +5,7 @@ export default class BuildingEditRoute extends Route {
5
5
  return {
6
6
  buildingId,
7
7
  projectId: this.modelFor("building"),
8
- instanceId: this.modelFor("application").id,
8
+ instanceId: this.modelFor("application")?.id,
9
9
  };
10
10
  }
11
11
  }
@@ -18,7 +18,7 @@ export default class BuildingNewRoute extends BuildingFormRoute {
18
18
 
19
19
  async model() {
20
20
  const model = {
21
- instanceId: this.modelFor("application").id,
21
+ instanceId: this.modelFor("application")?.id,
22
22
  projectId: this.modelFor("building"),
23
23
  };
24
24
  const buildingWork = new BuildingWork();
@@ -1,7 +1,12 @@
1
1
  import Route from "@ember/routing/route";
2
2
 
3
3
  export default class BuildingRoute extends Route {
4
- model({ project_id }) {
5
- return project_id;
4
+ queryParams = {
5
+ projectId: {
6
+ refreshModel: true,
7
+ },
8
+ };
9
+ model({ projectId }) {
10
+ return projectId;
6
11
  }
7
12
  }
@@ -0,0 +1,9 @@
1
+ import Route from "@ember/routing/route";
2
+
3
+ export default class GlobalLandingPageRoute extends Route {
4
+ afterModel({ id } = {}) {
5
+ if (typeof id === "string") {
6
+ this.transitionTo("project");
7
+ }
8
+ }
9
+ }
@@ -4,7 +4,7 @@ export default class ProjectErrorsRoute extends Route {
4
4
  model({ project_id: projectId }) {
5
5
  return {
6
6
  projectId,
7
- instanceId: this.modelFor("application").id,
7
+ instanceId: this.modelFor("application")?.id,
8
8
  };
9
9
  }
10
10
 
@@ -4,7 +4,7 @@ export default class ProjectFormRoute extends Route {
4
4
  model({ project_id: projectId }) {
5
5
  return {
6
6
  projectId,
7
- instanceId: this.modelFor("application").id,
7
+ instanceId: this.modelFor("application")?.id,
8
8
  };
9
9
  }
10
10
 
@@ -19,6 +19,6 @@ export default class ProjectNewRoute extends FormRoute {
19
19
  this.config.cantonAbbreviation;
20
20
  project.constructionSurveyDeptNumber =
21
21
  this.constructionProject.constructionSurveyDeptNumber;
22
- return { project, instanceId: this.modelFor("application").id };
22
+ return { project, instanceId: this.modelFor("application")?.id };
23
23
  }
24
24
  }
@@ -2,6 +2,6 @@ import Route from "@ember/routing/route";
2
2
 
3
3
  export default class ProjectRoute extends Route {
4
4
  model() {
5
- return this.modelFor("application").id;
5
+ return this.modelFor("application")?.id;
6
6
  }
7
7
  }
@@ -0,0 +1,3 @@
1
+ import Route from "@ember/routing/route";
2
+
3
+ export default class QuarterlyClosureRoute extends Route {}
@@ -1,7 +1,12 @@
1
1
  import Route from "@ember/routing/route";
2
2
 
3
3
  export default class SearchBuildingRoute extends Route {
4
- model({ project_id }) {
5
- return project_id;
4
+ queryParams = {
5
+ projectId: {
6
+ refreshModel: true,
7
+ },
8
+ };
9
+ model({ projectId }) {
10
+ return projectId;
6
11
  }
7
12
  }
package/addon/routes.js CHANGED
@@ -1,15 +1,19 @@
1
1
  import buildRoutes from "ember-engines/routes";
2
2
 
3
3
  export default buildRoutes(function () {
4
+ this.route("global-landing-page", { path: "/" });
5
+ this.route("quarterly-closure");
6
+
4
7
  this.route("search-project");
5
- this.route("search-building", { path: "/:project_id/search-building" });
6
- this.route("project", { path: "/" }, function () {
8
+ this.route("search-building");
9
+
10
+ this.route("project", { path: "/projects" }, function () {
7
11
  this.route("form", { path: "/:project_id/form" });
8
12
  this.route("new");
9
13
  this.route("linked-buildings", { path: "/:project_id/buildings" });
10
14
  this.route("errors", { path: "/:project_id/errors" });
11
15
  });
12
- this.route("building", { path: "/:project_id/building/" }, function () {
16
+ this.route("building", function () {
13
17
  this.route("new");
14
18
  this.route("edit", { path: "/:building_id" }, function () {
15
19
  this.route("form");
@@ -11,6 +11,11 @@ export default class AuthFetchService extends Service {
11
11
  @tracked showAuthModal = false;
12
12
  @tracked token;
13
13
  @tracked municipality;
14
+ @tracked username;
15
+
16
+ get constructionSurveyDeptNumber() {
17
+ return this.municipality && `${this.municipality}00`;
18
+ }
14
19
 
15
20
  constructor(...args) {
16
21
  super(...args);
@@ -25,13 +30,6 @@ export default class AuthFetchService extends Service {
25
30
 
26
31
  @task
27
32
  *housingStatToken(username, password, municipality) {
28
- if (
29
- this.config.username &&
30
- this.config.password &&
31
- this.config.municipality
32
- ) {
33
- ({ username, password, municipality } = this.config);
34
- }
35
33
  const response = yield fetch(`/api/v1/housing-stat-token`, {
36
34
  method: "post",
37
35
  headers: {
@@ -69,6 +67,7 @@ export default class AuthFetchService extends Service {
69
67
 
70
68
  this.token = json.token;
71
69
  this.municipality = json.municipality;
70
+ this.username = json.username;
72
71
  return json;
73
72
  }
74
73
 
@@ -166,6 +166,16 @@ export default class ConstructionProjectService extends GwrService {
166
166
  return projects;
167
167
  }
168
168
 
169
+ async removeProjectLink(projectId) {
170
+ const link = this.store
171
+ .peekAll("gwr-link")
172
+ .find(({ eproid }) => Number(eproid) === projectId);
173
+ await link.destroyRecord();
174
+ this.all.lastSuccessful.value = this.all.lastSuccessful.value.filter(
175
+ (project) => project.EPROID !== projectId
176
+ );
177
+ }
178
+
169
179
  async search(query = {}) {
170
180
  return super.search(query, query.EPROID, {
171
181
  xmlMethod: "getConstructionProject",
@@ -12,6 +12,10 @@ export default class GwrService extends Service {
12
12
  @service xml;
13
13
  @service intl;
14
14
 
15
+ get pageSize() {
16
+ return this.config.pageSize;
17
+ }
18
+
15
19
  _cache = {};
16
20
 
17
21
  get municipality() {
@@ -19,7 +23,7 @@ export default class GwrService extends Service {
19
23
  }
20
24
 
21
25
  get constructionSurveyDeptNumber() {
22
- return `${this.municipality}00`;
26
+ return this.authFetch.constructionSurveyDeptNumber;
23
27
  }
24
28
 
25
29
  createAndCache(xml) {
@@ -56,7 +60,7 @@ export default class GwrService extends Service {
56
60
  }
57
61
 
58
62
  async search(
59
- query = {},
63
+ query,
60
64
  id,
61
65
  { xmlMethod, urlPath, listModel, listKey, searchKey }
62
66
  ) {
@@ -71,14 +75,22 @@ export default class GwrService extends Service {
71
75
  }
72
76
  // We replace the newlines since they would be encoded in the query param
73
77
  // and this would break the xml.
78
+
79
+ // https://localhost:9090/regbl/api/ech0216/2/buildings?page=0&size=10&sortColumn=geb_egid&sortDirection=asc
74
80
  const queryXML = this.xml
75
81
  .buildXMLRequest(xmlMethod, query)
76
82
  .replace(/\r?\n|\r/g, "");
77
- response = await this.authFetch.fetch(`/${urlPath}/`, {
78
- headers: {
79
- query: queryXML,
80
- },
81
- });
83
+
84
+ response = await this.authFetch.fetch(
85
+ query.page
86
+ ? `/${urlPath}?page=${query.page}&size=${this.pageSize}`
87
+ : `/${urlPath}`,
88
+ {
89
+ headers: {
90
+ query: queryXML,
91
+ },
92
+ }
93
+ );
82
94
  // The api returns a 404 if no results are found for the query
83
95
  if (!response.ok && response.status === 404) {
84
96
  return [];
@@ -0,0 +1,147 @@
1
+ import { later } from "@ember/runloop";
2
+ import Service, { inject as service } from "@ember/service";
3
+ import { tracked } from "@glimmer/tracking";
4
+ import CheckConstructionProjectResponse from "ember-ebau-gwr/models/check-construction-project-response";
5
+ import CheckSurveyDepartmentResponse from "ember-ebau-gwr/models/check-survey-department-response";
6
+ import QuarterlyClosureStatus, {
7
+ STATUS_TYPES,
8
+ REQUEST_PENDING,
9
+ } from "ember-ebau-gwr/models/quarterly-closure-status";
10
+
11
+ export default class QuarterlyClosureService extends Service {
12
+ @service authFetch;
13
+ @service intl;
14
+ @service notification;
15
+
16
+ @tracked quarterlyClosureStatus;
17
+
18
+ get status() {
19
+ const id = this.quarterlyClosureStatus?.surveyStatus;
20
+ const status = {
21
+ id,
22
+ type: STATUS_TYPES[id],
23
+ };
24
+
25
+ if (id === REQUEST_PENDING) {
26
+ return {
27
+ type: REQUEST_PENDING,
28
+ label: this.intl.t(`ember-gwr.quarterlyClosure.status.processing`),
29
+ shortLabel: this.intl.t(
30
+ `ember-gwr.quarterlyClosure.status.short.processing`
31
+ ),
32
+ };
33
+ }
34
+
35
+ if (!id) {
36
+ const label = this.intl.t(`ember-gwr.quarterlyClosure.status.loading`);
37
+ return { ...status, label, shortLabel: label, isLoading: true };
38
+ }
39
+
40
+ return {
41
+ ...status,
42
+ label: this.intl.t(`ember-gwr.quarterlyClosure.status.${id}`),
43
+ shortLabel: this.intl.t(`ember-gwr.quarterlyClosure.status.short.${id}`),
44
+ };
45
+ }
46
+
47
+ get disableForms() {
48
+ return ![620, 630, 650, 651, 663, 665, 690].includes(this.status.id);
49
+ }
50
+
51
+ get constructionSurveyDeptNumber() {
52
+ return this.authFetch.constructionSurveyDeptNumber;
53
+ }
54
+
55
+ constructor(...args) {
56
+ super(...args);
57
+ this.pollProgressStatus();
58
+ }
59
+
60
+ async pollProgressStatus() {
61
+ if (this.constructionSurveyDeptNumber) {
62
+ try {
63
+ this.quarterlyClosureStatus = await this.getProgressStatus();
64
+ later(
65
+ this,
66
+ this.pollProgressStatus,
67
+ this.status.type === REQUEST_PENDING
68
+ ? 5000 //5sec
69
+ : 1800000 // 30min
70
+ );
71
+ } catch (error) {
72
+ console.error(error);
73
+ this.notification.danger(
74
+ this.intl.t("ember-gwr.quarterlyClosure.status.pollError")
75
+ );
76
+ later(
77
+ this,
78
+ this.pollProgressStatus,
79
+ 60000 // 1min
80
+ );
81
+ }
82
+ } else {
83
+ // If the authFetch is not yet setup we just try again in 100ms
84
+ later(this, this.pollProgressStatus, 100);
85
+ }
86
+ }
87
+
88
+ async getProgressStatus() {
89
+ if (!this.constructionSurveyDeptNumber) {
90
+ return null;
91
+ }
92
+
93
+ const response = await this.authFetch.fetch(
94
+ `/constructionsurveydepts/${this.constructionSurveyDeptNumber}/getProgressStatusQuarterlyClosure`,
95
+ { method: "get" }
96
+ );
97
+ const quarterlyClosureStatus = new QuarterlyClosureStatus(
98
+ await response.text()
99
+ );
100
+
101
+ if (quarterlyClosureStatus.error?.length) {
102
+ if (response.ok && quarterlyClosureStatus.error?.length) {
103
+ const stillRunningStatus = new QuarterlyClosureStatus();
104
+ stillRunningStatus.surveyStatus = REQUEST_PENDING;
105
+ return stillRunningStatus;
106
+ }
107
+ const errors = quarterlyClosureStatus.error;
108
+ throw errors;
109
+ }
110
+
111
+ return quarterlyClosureStatus;
112
+ }
113
+
114
+ async close() {
115
+ if (!this.constructionSurveyDeptNumber) {
116
+ return null;
117
+ }
118
+
119
+ const response = await this.authFetch.fetch(
120
+ `/constructionsurveydepts/${this.constructionSurveyDeptNumber}/closeQuarterlySurvey`,
121
+ { method: "put" }
122
+ );
123
+ this.quarterlyClosureStatus = new QuarterlyClosureStatus(
124
+ await response.text()
125
+ );
126
+ }
127
+
128
+ async checkQuarterlySurveyDept() {
129
+ if (!this.constructionSurveyDeptNumber) {
130
+ return null;
131
+ }
132
+
133
+ const response = await this.authFetch.fetch(
134
+ `/constructionsurveydepts/${this.constructionSurveyDeptNumber}/check`,
135
+ { method: "put" }
136
+ );
137
+ return new CheckSurveyDepartmentResponse(await response.text());
138
+ }
139
+
140
+ async checkConstructionProject(id) {
141
+ const response = await this.authFetch.fetch(
142
+ `/constructionprojects/${id}/check`,
143
+ { method: "put" }
144
+ );
145
+ return new CheckConstructionProjectResponse(await response.text());
146
+ }
147
+ }