ember-ebau-gwr 2.7.1 → 3.2.0

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 (116) hide show
  1. package/.github/workflows/release.yml +2 -0
  2. package/CHANGELOG.md +95 -0
  3. package/addon/components/back-route.hbs +10 -0
  4. package/addon/components/import-modal/building-data.hbs +64 -0
  5. package/addon/components/import-modal/dwelling-data.hbs +30 -0
  6. package/addon/components/import-modal/entrance-data.hbs +14 -0
  7. package/addon/components/import-modal.hbs +54 -0
  8. package/addon/components/import-modal.js +6 -0
  9. package/addon/components/link-building-modal.hbs +1 -1
  10. package/addon/components/link-building-modal.js +2 -0
  11. package/addon/components/link-street.hbs +105 -0
  12. package/addon/components/link-street.js +24 -0
  13. package/addon/components/linked-models.hbs +12 -6
  14. package/addon/components/linked-models.js +6 -0
  15. package/addon/components/linked-projects.hbs +1 -1
  16. package/addon/components/linked-projects.js +6 -0
  17. package/addon/components/model-errors/error-indicator.hbs +3 -1
  18. package/addon/components/model-errors/header.hbs +4 -2
  19. package/addon/components/model-errors.hbs +1 -0
  20. package/addon/components/model-form/date.hbs +1 -0
  21. package/addon/components/model-form/date.js +6 -6
  22. package/addon/components/model-form/diff.hbs +40 -27
  23. package/addon/components/model-form/field.hbs +13 -8
  24. package/addon/components/model-form/field.js +36 -9
  25. package/addon/components/model-form/header/actions.hbs +70 -36
  26. package/addon/components/model-form/header/actions.js +6 -0
  27. package/addon/components/model-form/header/status-selector/submit-parameters.hbs +1 -1
  28. package/addon/components/model-form/header/status-selector.hbs +1 -1
  29. package/addon/components/model-form/header.hbs +4 -2
  30. package/addon/components/model-form/submit-errors.hbs +41 -23
  31. package/addon/components/model-form.hbs +6 -5
  32. package/addon/components/model-form.js +25 -5
  33. package/addon/components/model-inview.hbs +8 -0
  34. package/addon/components/model-inview.js +12 -0
  35. package/addon/components/project-form/date.hbs +1 -1
  36. package/addon/components/project-form/field.hbs +1 -1
  37. package/addon/components/project-form/field.js +5 -1
  38. package/addon/components/search/filters.hbs +0 -5
  39. package/addon/components/search/filters.js +1 -3
  40. package/addon/components/sub-nav.hbs +5 -10
  41. package/addon/controllers/building/edit/dwelling/edit.js +27 -32
  42. package/addon/controllers/building/edit/dwellings.js +1 -1
  43. package/addon/controllers/building/edit/entrance/edit/index.js +26 -13
  44. package/addon/controllers/building/edit/entrance/edit/link-street.js +45 -20
  45. package/addon/controllers/building/edit/entrances.js +18 -2
  46. package/addon/controllers/building/edit/form.js +29 -44
  47. package/addon/controllers/import.js +70 -0
  48. package/addon/controllers/project/errors.js +25 -29
  49. package/addon/controllers/project/form.js +35 -48
  50. package/addon/controllers/project.js +2 -1
  51. package/addon/helpers/housing-stat-link.js +13 -0
  52. package/addon/helpers/is-unset.js +7 -0
  53. package/addon/helpers/show-model-field.js +13 -0
  54. package/addon/models/address.js +39 -9
  55. package/addon/models/building-entrance.js +17 -7
  56. package/addon/models/building.js +74 -75
  57. package/addon/models/client.js +1 -1
  58. package/addon/models/construction-project.js +18 -16
  59. package/addon/models/date-partially-known.js +1 -1
  60. package/addon/models/dwelling.js +28 -1
  61. package/addon/models/heating.js +1 -1
  62. package/addon/models/identification.js +2 -1
  63. package/addon/models/options.js +251 -1
  64. package/addon/models/organisation-identification.js +6 -3
  65. package/addon/models/realestate-identification.js +0 -6
  66. package/addon/models/street.js +2 -0
  67. package/addon/models/xml-model.js +18 -7
  68. package/addon/models.js +2 -1
  69. package/addon/routes/building/edit/entrance/edit/index.js +0 -2
  70. package/addon/routes/building/edit/entrance/edit/link-street.js +10 -1
  71. package/addon/routes/building/edit/entrance/new.js +9 -16
  72. package/addon/routes/building/edit/index.js +8 -1
  73. package/addon/routes/building/new.js +10 -1
  74. package/addon/routes/project/form.js +5 -0
  75. package/addon/routes/project/new.js +3 -2
  76. package/addon/services/building-entrance.js +13 -9
  77. package/addon/services/building.js +195 -193
  78. package/addon/services/construction-project.js +140 -152
  79. package/addon/services/gwr.js +47 -2
  80. package/addon/services/street.js +10 -0
  81. package/addon/templates/building/edit/dwelling/edit.hbs +29 -6
  82. package/addon/templates/building/edit/dwellings.hbs +7 -4
  83. package/addon/templates/building/edit/entrance/edit/index.hbs +49 -84
  84. package/addon/templates/building/edit/entrance/edit/link-street.hbs +41 -12
  85. package/addon/templates/building/edit/entrances.hbs +6 -3
  86. package/addon/templates/building/edit/form.hbs +75 -21
  87. package/addon/templates/project/errors.hbs +121 -132
  88. package/addon/templates/project/form.hbs +126 -97
  89. package/addon/templates/project/linked-buildings.hbs +13 -20
  90. package/addon/templates/project.hbs +29 -19
  91. package/addon/templates/search-building.hbs +6 -0
  92. package/addon/templates/search-project.hbs +6 -0
  93. package/addon/utils.js +8 -0
  94. package/addon/validations/building-entrance.js +6 -4
  95. package/addon/validations/building-work.js +131 -11
  96. package/addon/validations/construction-project.js +154 -6
  97. package/addon/validations/coordinates.js +2 -2
  98. package/addon/validations/dwelling.js +61 -6
  99. package/addon/validations/realestate-identification.js +9 -9
  100. package/addon/validations/status/status-project-change.js +1 -1
  101. package/addon/validations/status/status-project-correction.js +1 -1
  102. package/addon/validators/range-state.js +27 -0
  103. package/addon/xml/helpers.js +4 -0
  104. package/addon/xml/templates/building-entrance.js +0 -14
  105. package/addon/xml/templates/building.js +0 -6
  106. package/addon/xml/templates/construction-project.js +2 -9
  107. package/addon/xml/templates/street.js +1 -7
  108. package/app/styles/ember-ebau-gwr.scss +32 -5
  109. package/config/environment.js +3 -0
  110. package/package.json +2 -2
  111. package/translations/building/de.yaml +13 -8
  112. package/translations/building-entrance/de.yaml +4 -10
  113. package/translations/construction-project/de.yaml +270 -15
  114. package/translations/de.yaml +46 -13
  115. package/translations/dwelling/de.yaml +14 -0
  116. package/translations/locality/de.yaml +2 -0
@@ -1,14 +1,9 @@
1
1
  {{#unless this.isHidden}}
2
- {{#if @backRoute}}
3
- <LinkTo
4
- @route={{@backRoute}}
5
- @models={{if @backModel (array @backModel) (array)}}
6
- class="uk-link-muted uk-margin-small-bottom"
7
- >
8
- <span uk-icon="icon: arrow-left"></span>
9
- {{@backText}}
10
- </LinkTo>
11
- {{/if}}
2
+ <BackRoute
3
+ @backRoute={{@backRoute}}
4
+ @backModel={{@backModel}}
5
+ @backText={{@backText}}
6
+ />
12
7
  <UkTab ...attributes as |Tab|>
13
8
  {{#each @links as |link|}}
14
9
  <Tab.link-item @route={{link.route}} @models={{link.models}}>
@@ -1,18 +1,20 @@
1
- import Controller from "@ember/controller";
2
1
  import { action } from "@ember/object";
3
2
  import { inject as service } from "@ember/service";
4
3
  import { tracked } from "@glimmer/tracking";
5
4
  import { task, dropTask, lastValue } from "ember-concurrency-decorators";
5
+ import ImportController from "ember-ebau-gwr/controllers/import";
6
6
  import Models from "ember-ebau-gwr/models";
7
7
  import Dwelling from "ember-ebau-gwr/models/dwelling";
8
8
  import DwellingValidations from "ember-ebau-gwr/validations/dwelling";
9
9
 
10
- export default class BuildingEditDwellingEditController extends Controller {
10
+ export default class BuildingEditDwellingEditController extends ImportController {
11
+ importModelName = "dwelling";
11
12
  Models = Models;
12
13
  DwellingValidations = DwellingValidations;
13
14
 
14
15
  @service("dwelling") dwellingAPI;
15
16
  @service building;
17
+ @service gwr;
16
18
  @service intl;
17
19
  @service notification;
18
20
  @service router;
@@ -34,6 +36,7 @@ export default class BuildingEditDwellingEditController extends Controller {
34
36
  try {
35
37
  this.errors = [];
36
38
 
39
+ yield this.fetchCalumaData.perform();
37
40
  yield this.fetchEntrances.perform();
38
41
  if (this.model.dwelling?.isNew) {
39
42
  this.model.dwelling.EDID = this.entrances[0].EDID;
@@ -46,6 +49,7 @@ export default class BuildingEditDwellingEditController extends Controller {
46
49
  );
47
50
  dwelling.oldEDID = EDID;
48
51
 
52
+ this.errors = [];
49
53
  return dwelling;
50
54
  } catch (error) {
51
55
  console.error(error);
@@ -53,6 +57,15 @@ export default class BuildingEditDwellingEditController extends Controller {
53
57
  }
54
58
  }
55
59
 
60
+ get entranceOptions() {
61
+ return this.entrances.map((entrance) => ({
62
+ EDID: entrance.EDID,
63
+ label: `${this.intl.t("ember-gwr.buildingEntrance.title", {
64
+ address: entrance.EDID,
65
+ })} - ${entrance.fullAddressText}`,
66
+ }));
67
+ }
68
+
56
69
  @lastValue("fetchEntrances") entrances;
57
70
  @task
58
71
  *fetchEntrances() {
@@ -69,9 +82,16 @@ export default class BuildingEditDwellingEditController extends Controller {
69
82
  }
70
83
  }
71
84
 
85
+ @action
86
+ cancelMerge() {
87
+ this.resetImport();
88
+ this.fetchDwelling.perform();
89
+ }
90
+
72
91
  @dropTask
73
92
  *saveDwelling() {
74
93
  try {
94
+ this.dwelling.floor = this.dwelling.floorComplete;
75
95
  if (this.dwelling.isNew) {
76
96
  const dwelling = yield this.dwellingAPI.create(
77
97
  this.dwelling,
@@ -87,6 +107,8 @@ export default class BuildingEditDwellingEditController extends Controller {
87
107
  );
88
108
  }
89
109
  }
110
+ // Ensure dwelling list is refreshed
111
+ this.building.clearCache(this.model.buildingId);
90
112
  this.errors = [];
91
113
  this.notification.success(this.intl.t("ember-gwr.dwelling.saveSuccess"));
92
114
  } catch (error) {
@@ -95,18 +117,6 @@ export default class BuildingEditDwellingEditController extends Controller {
95
117
  }
96
118
  }
97
119
 
98
- concatStates(states) {
99
- if (states.length === 1) {
100
- return this.intl.t(`ember-gwr.lifeCycles.states.${states[0]}`);
101
- }
102
- const tail = states.pop();
103
- return `${states
104
- .map((state) => this.intl.t(`ember-gwr.lifeCycles.states.${state}`))
105
- .join(", ")} ${this.intl.t("ember-gwr.general.or")} ${this.intl.t(
106
- `ember-gwr.lifeCycles.states.${tail}`
107
- )}`;
108
- }
109
-
110
120
  @task
111
121
  *transitionState(currentStatus, newStatus) {
112
122
  try {
@@ -141,24 +151,9 @@ export default class BuildingEditDwellingEditController extends Controller {
141
151
  console.error(error);
142
152
  this.notification.danger(this.intl.t("ember-gwr.dwelling.saveError"));
143
153
 
144
- if (error.isLifeCycleError) {
145
- const errorType = error.dwellingId
146
- ? "statusErrorDwelling"
147
- : "statusErrorBuilding";
148
- throw [
149
- this.intl.t(`ember-gwr.lifeCycles.${errorType}`, {
150
- dwellingId: error.dwellingId,
151
- buildingId: error.buildingId,
152
- states: this.concatStates(error.states),
153
- href: error.dwellingId
154
- ? `/${this.model.instanceId}/${this.model.projectId}/building/${error.buildingId}/dwelling/${error.dwellingId}`
155
- : `/${this.model.instanceId}/${this.model.projectId}/building/${error.buildingId}/form`,
156
- htmlSafe: true,
157
- }),
158
- ];
159
- }
160
-
161
- throw error;
154
+ throw error.isLifeCycleError
155
+ ? this.gwr.buildLifeCycleError(error, this.model)
156
+ : error;
162
157
  }
163
158
  }
164
159
 
@@ -15,7 +15,7 @@ export default class BuildingEditDwellingsController extends Controller {
15
15
  const building = yield this.building.getFromCacheOrApi(this.model);
16
16
  return building.buildingEntrance.flatMap((entrance) =>
17
17
  entrance.dwelling.map((dwelling) => {
18
- dwelling.buildingEntranceNo = entrance.buildingEntranceNo;
18
+ dwelling.buildingEntrance = entrance;
19
19
  return dwelling;
20
20
  })
21
21
  );
@@ -1,11 +1,13 @@
1
- import Controller from "@ember/controller";
1
+ import { action } from "@ember/object";
2
2
  import { inject as service } from "@ember/service";
3
3
  import { tracked } from "@glimmer/tracking";
4
4
  import { task, dropTask, lastValue } from "ember-concurrency-decorators";
5
+ import ImportController from "ember-ebau-gwr/controllers/import";
5
6
  import Models from "ember-ebau-gwr/models";
6
7
  import BuildingEntranceValidations from "ember-ebau-gwr/validations/building-entrance";
7
8
 
8
- export default class BuildingEditEntranceEditIndexController extends Controller {
9
+ export default class BuildingEditEntranceEditIndexController extends ImportController {
10
+ importModelName = "buildingEntrance";
9
11
  Models = Models;
10
12
  BuildingEntranceValidations = BuildingEntranceValidations;
11
13
 
@@ -14,6 +16,7 @@ export default class BuildingEditEntranceEditIndexController extends Controller
14
16
  @service intl;
15
17
  @service notification;
16
18
  @service router;
19
+ @service config;
17
20
 
18
21
  @tracked errors;
19
22
 
@@ -22,18 +25,16 @@ export default class BuildingEditEntranceEditIndexController extends Controller
22
25
  *fetchBuildingEntrance() {
23
26
  try {
24
27
  this.errors = [];
25
- let buildingEntrance;
26
-
27
- if (this.buildingEntranceAPI.newRecord) {
28
- buildingEntrance = this.buildingEntranceAPI.newRecord;
29
- } else {
30
- buildingEntrance = yield this.buildingEntranceAPI.getFromCacheOrApi(
31
- this.model.entranceId,
32
- this.model.buildingId
33
- );
34
-
35
- buildingEntrance.EGID = this.model.buildingId;
28
+ yield this.fetchCalumaData.perform();
29
+ if (this.model.buildingEntrance?.isNew) {
30
+ return this.model.buildingEntrance;
36
31
  }
32
+ const buildingEntrance = yield this.buildingEntranceAPI.getFromCacheOrApi(
33
+ this.model.entranceId,
34
+ this.model.buildingId
35
+ );
36
+
37
+ buildingEntrance.EGID = this.model.buildingId;
37
38
  return buildingEntrance;
38
39
  } catch (error) {
39
40
  console.error(error);
@@ -43,6 +44,12 @@ export default class BuildingEditEntranceEditIndexController extends Controller
43
44
  }
44
45
  }
45
46
 
47
+ @action
48
+ cancelMerge() {
49
+ this.resetImport();
50
+ this.fetchBuildingEntrance.perform();
51
+ }
52
+
46
53
  @dropTask
47
54
  *saveBuildingEntrance() {
48
55
  try {
@@ -61,6 +68,8 @@ export default class BuildingEditEntranceEditIndexController extends Controller
61
68
  this.model.buildingId
62
69
  );
63
70
  }
71
+ // Ensure building entrance list is refreshed
72
+ this.building.clearCache(this.model.buildingId);
64
73
  this.errors = [];
65
74
  this.notification.success(
66
75
  this.intl.t("ember-gwr.buildingEntrance.saveSuccess")
@@ -72,4 +81,8 @@ export default class BuildingEditEntranceEditIndexController extends Controller
72
81
  );
73
82
  }
74
83
  }
84
+
85
+ get hasNoStreet() {
86
+ return !this.buildingEntrance?.isNew && this.buildingEntrance?.street.isNew;
87
+ }
75
88
  }
@@ -1,28 +1,56 @@
1
1
  import Controller from "@ember/controller";
2
2
  import { action } from "@ember/object";
3
3
  import { inject as service } from "@ember/service";
4
+ import { tracked } from "@glimmer/tracking";
4
5
  import { task, lastValue } from "ember-concurrency-decorators";
5
6
  import { languageOptions } from "ember-ebau-gwr/models/options";
6
7
 
7
8
  export default class BuildingEditEntranceLinkStreetController extends Controller {
9
+ queryParams = ["locality", "PLZ4", "PLZ6"];
10
+
8
11
  @service street;
9
12
  @service buildingEntrance;
13
+ @service building;
10
14
  @service notification;
11
15
  @service intl;
12
16
 
17
+ // A locality is uniquely described by either
18
+ // locality name + PLZ4 or PLZ4 + PLZ6
19
+ @tracked locality = null;
20
+ @tracked PLZ4 = null;
21
+ @tracked PLZ6 = null;
22
+
13
23
  get baseQuery() {
14
24
  return {
15
25
  description: {},
16
- locality: { name: {} },
26
+ locality: {
27
+ swissZipCode: this.PLZ4,
28
+ swissZipCodeAddOn: this.PLZ6,
29
+ name: {
30
+ nameLong: this.locality,
31
+ },
32
+ },
17
33
  };
18
34
  }
19
35
 
20
36
  get backRoute() {
37
+ if (this.model.buildingId === "new") {
38
+ return "building.new";
39
+ }
40
+
21
41
  return `building.edit.entrance.${
22
- this.buildingEntrance.newRecord ? "new" : "edit.index"
42
+ this.buildingEntrance.isNew ? "new" : "edit.index"
23
43
  }`;
24
44
  }
25
45
 
46
+ get backRouteLabel() {
47
+ return this.intl.t(
48
+ `ember-gwr.buildingEntrance.${
49
+ this.model.buildingId === "new" ? "backToBuilding" : "backToEntrance"
50
+ }`
51
+ );
52
+ }
53
+
26
54
  @lastValue("search") searchResults;
27
55
  @task
28
56
  *search(query) {
@@ -40,29 +68,26 @@ export default class BuildingEditEntranceLinkStreetController extends Controller
40
68
  @action
41
69
  async setStreet(street) {
42
70
  try {
43
- if (this.buildingEntrance.newRecord) {
44
- this.buildingEntrance.newRecord.street = street;
45
- this.transitionToRoute("building.edit.entrance.new");
46
- } else {
47
- const entrance = await this.buildingEntrance.getFromCacheOrApi(
48
- this.model.entranceId,
49
- this.model.buildingId
50
- );
51
- await this.buildingEntrance.setStreet(
52
- this.model.entranceId,
53
- this.model.buildingId,
54
- entrance.EGAID,
55
- street
56
- );
57
- this.transitionToRoute("building.edit.entrance.edit.index");
58
- }
71
+ const entrance = await this.buildingEntrance.getFromCacheOrApi(
72
+ this.model.entranceId,
73
+ this.model.buildingId
74
+ );
75
+ entrance.street = street;
76
+ await this.buildingEntrance.setStreet(
77
+ this.model.entranceId,
78
+ this.model.buildingId,
79
+ entrance
80
+ );
81
+ // Ensure building entrance list is updated
82
+ this.building.clearCache(this.model.buildingId);
83
+ this.transitionToRoute(this.backRoute);
59
84
  this.notification.success(
60
- this.intl.t("ember-gwr.buildingEntrance.linkStreet.linkSuccess")
85
+ this.intl.t("ember-gwr.components.linkStreet.linkSuccess")
61
86
  );
62
87
  } catch (error) {
63
88
  console.error(error);
64
89
  this.notification.danger(
65
- this.intl.t("ember-gwr.buildingEntrance.linkStreet.linkError")
90
+ this.intl.t("ember-gwr.components.linkStreet.linkError")
66
91
  );
67
92
  }
68
93
  }
@@ -1,14 +1,18 @@
1
1
  import Controller from "@ember/controller";
2
2
  import { action } from "@ember/object";
3
3
  import { inject as service } from "@ember/service";
4
- import { task } from "ember-concurrency-decorators";
4
+ import { lastValue, task } from "ember-concurrency-decorators";
5
+ import BuildingEntrance from "ember-ebau-gwr/models/building-entrance";
5
6
 
6
7
  export default class BuildingEntrancesIndexController extends Controller {
8
+ BuildingEntrance = BuildingEntrance;
9
+
7
10
  @service building;
8
11
  @service buildingEntrance;
9
12
  @service intl;
10
13
  @service notification;
11
14
 
15
+ @lastValue("fetchEntrances") entrances;
12
16
  @task
13
17
  *fetchEntrances() {
14
18
  try {
@@ -27,10 +31,22 @@ export default class BuildingEntrancesIndexController extends Controller {
27
31
  try {
28
32
  await this.buildingEntrance.deactivate(EDID, this.model);
29
33
  await this.fetchEntrances.perform();
34
+ this.notification.success(
35
+ this.intl.t("ember-gwr.building.entrances.removeLinkSuccess")
36
+ );
30
37
  } catch (error) {
31
38
  console.error(error);
39
+ // Check if error occurred due to active dwellings attached to the
40
+ // building entrance. TODO: find a way to check for active dwellings
41
+ // before executing the request
32
42
  this.notification.danger(
33
- this.intl.t("ember-gwr.linkedBuildings.removeLinkError")
43
+ this.intl.t(
44
+ `ember-gwr.${
45
+ error[0] === this.BuildingEntrance.DEACTIVATION_ERROR
46
+ ? "building.entrances.attachedDwellingsError"
47
+ : "linkedBuildings.removeLinkError"
48
+ }`
49
+ )
34
50
  );
35
51
  }
36
52
  }
@@ -1,22 +1,25 @@
1
- import Controller from "@ember/controller";
2
1
  import { action } from "@ember/object";
3
2
  import { inject as service } from "@ember/service";
4
3
  import { tracked } from "@glimmer/tracking";
5
4
  import { task, dropTask, lastValue } from "ember-concurrency-decorators";
5
+ import ImportController from "ember-ebau-gwr/controllers/import";
6
6
  import Models from "ember-ebau-gwr/models";
7
7
  import Building from "ember-ebau-gwr/models/building";
8
- import BuildingWorkValidations from "ember-ebau-gwr/validations/building-work";
8
+ import { buildingWorkValidation } from "ember-ebau-gwr/validations/building-work";
9
9
 
10
- export default class BuildingFormController extends Controller {
10
+ export default class BuildingFormController extends ImportController {
11
11
  Models = Models;
12
- BuildingWorkValidations = BuildingWorkValidations;
12
+
13
+ importModelName = "building";
13
14
 
14
15
  @service constructionProject;
15
16
  @service("building") buildingAPI;
16
17
  @service dwelling;
18
+ @service gwr;
17
19
  @service intl;
18
20
  @service notification;
19
21
 
22
+ @tracked BuildingWorkValidations;
20
23
  @tracked errors;
21
24
 
22
25
  get buildingStatusOptions() {
@@ -35,6 +38,10 @@ export default class BuildingFormController extends Controller {
35
38
  *fetchBuildingWork() {
36
39
  try {
37
40
  this.errors = [];
41
+ this.fetchCalumaData.perform();
42
+ this.BuildingWorkValidations = buildingWorkValidation(
43
+ this.model.buildingWork?.isNew
44
+ );
38
45
  yield this.fetchBuilding.perform();
39
46
 
40
47
  if (this.model.buildingWork?.isNew) {
@@ -45,6 +52,8 @@ export default class BuildingFormController extends Controller {
45
52
  this.model.projectId
46
53
  );
47
54
 
55
+ yield this.fetchBuilding.perform();
56
+
48
57
  return project.work?.find(
49
58
  (buildingWork) =>
50
59
  buildingWork.building.EGID === Number(this.model.buildingId)
@@ -69,6 +78,12 @@ export default class BuildingFormController extends Controller {
69
78
  return building;
70
79
  }
71
80
 
81
+ @action
82
+ cancelMerge() {
83
+ this.resetImport();
84
+ this.fetchBuildingWork.perform();
85
+ }
86
+
72
87
  @dropTask
73
88
  *saveBuildingWork() {
74
89
  try {
@@ -81,12 +96,14 @@ export default class BuildingFormController extends Controller {
81
96
  EGID = building.EGID;
82
97
  } else {
83
98
  yield this.buildingAPI.update(this.buildingWork.building);
99
+ // Only modify work if of type Umbau (only possible there)
100
+ if (this.buildingWork.kindOfWork === 6002) {
101
+ yield this.constructionProject.modifyWork(
102
+ this.model.projectId,
103
+ this.buildingWork
104
+ );
105
+ }
84
106
  }
85
- yield this.buildingAPI.bindBuildingToConstructionProject(
86
- this.model.projectId,
87
- EGID,
88
- this.buildingWork
89
- );
90
107
 
91
108
  // refresh work list
92
109
  const project = yield this.constructionProject.get(this.model.projectId);
@@ -117,18 +134,6 @@ export default class BuildingFormController extends Controller {
117
134
  }
118
135
  }
119
136
 
120
- concatStates(states) {
121
- if (states.length === 1) {
122
- return this.intl.t(`ember-gwr.lifeCycles.states.${states[0]}`);
123
- }
124
- const tail = states.pop();
125
- return `${states
126
- .map((state) => this.intl.t(`ember-gwr.lifeCycles.states.${state}`))
127
- .join(", ")} ${this.intl.t("ember-gwr.general.or")} ${this.intl.t(
128
- `ember-gwr.lifeCycles.states.${tail}`
129
- )}`;
130
- }
131
-
132
137
  @task
133
138
  *transitionState(currentStatus, newStatus, isCascading) {
134
139
  try {
@@ -168,24 +173,9 @@ export default class BuildingFormController extends Controller {
168
173
  console.error(error);
169
174
  this.notification.danger(this.intl.t("ember-gwr.building.saveError"));
170
175
 
171
- if (error.isLifeCycleError) {
172
- const errorType = error.dwellingId
173
- ? "statusErrorDwelling"
174
- : "statusErrorBuilding";
175
- throw [
176
- this.intl.t(`ember-gwr.lifeCycles.${errorType}`, {
177
- dwellingId: error.dwellingId,
178
- buildingId: error.buildingId,
179
- states: this.concatStates(error.states),
180
- href: error.dwellingId
181
- ? `/${this.model.instanceId}/${this.model.projectId}/building/${error.buildingId}/dwelling/${error.dwellingId}`
182
- : `/${this.model.instanceId}/${this.model.projectId}/building/${error.buildingId}/form`,
183
- htmlSafe: true,
184
- }),
185
- ];
186
- }
187
-
188
- throw error;
176
+ throw error.isLifeCycleError
177
+ ? this.gwr.buildLifeCycleError(error, this.model)
178
+ : error;
189
179
  }
190
180
  }
191
181
 
@@ -212,9 +202,4 @@ export default class BuildingFormController extends Controller {
212
202
  getCorrectionParameters(newStatus) {
213
203
  return this.buildingAPI.getCorrectionParameters(newStatus);
214
204
  }
215
-
216
- @action
217
- getChangeHint(currentStatus, newStatus) {
218
- return this.buildingAPI.getChangeHint(currentStatus, newStatus);
219
- }
220
205
  }
@@ -0,0 +1,70 @@
1
+ import Controller from "@ember/controller";
2
+ import { assert } from "@ember/debug";
3
+ import { inject as service } from "@ember/service";
4
+ import { tracked } from "@glimmer/tracking";
5
+ import { task, lastValue } from "ember-concurrency-decorators";
6
+
7
+ const IMPORT_MAP = {
8
+ project: "fetchProject",
9
+ building: "fetchBuildings",
10
+ dwelling: "fetchDwellings",
11
+ buildingEntrance: "fetchEntrances",
12
+ };
13
+
14
+ export default class ImportController extends Controller {
15
+ queryParams = [
16
+ {
17
+ showImport: "import",
18
+ importIndex: "index",
19
+ },
20
+ ];
21
+
22
+ @service dataImport;
23
+
24
+ @tracked showImport = false;
25
+ @tracked importIndex = undefined;
26
+
27
+ get import() {
28
+ if (this.showImport) {
29
+ assert("`fetchCalumaData` was never called.", this.importData);
30
+ }
31
+
32
+ const index = Number(this.importIndex);
33
+ const data =
34
+ Array.isArray(this.importData) && !isNaN(index)
35
+ ? this.importData[index]
36
+ : this.importData;
37
+
38
+ return this.showImport
39
+ ? {
40
+ index,
41
+ data,
42
+ originalData: this.importData,
43
+ }
44
+ : false;
45
+ }
46
+
47
+ resetImport() {
48
+ this.showImport = false;
49
+ this.importIndex = null;
50
+ }
51
+
52
+ @lastValue("fetchCalumaData") importData;
53
+ @task
54
+ *fetchCalumaData(...args) {
55
+ // Reset query params to clear singleton state
56
+ this.resetImport();
57
+ assert(
58
+ "Must set `importModelName` to a string.",
59
+ typeof this.importModelName === "string"
60
+ );
61
+ assert(
62
+ "Must set `instanceId` on model.",
63
+ this.model.instanceId !== null && this.model.instanceId !== undefined
64
+ );
65
+ return yield this.dataImport[IMPORT_MAP[this.importModelName]](
66
+ this.model.instanceId,
67
+ ...args
68
+ );
69
+ }
70
+ }
@@ -16,11 +16,6 @@ export default class ProjectErrorsController extends Controller {
16
16
  @service notification;
17
17
 
18
18
  @tracked projectErrorCount = 0;
19
- @tracked buildingErrorCount = {};
20
- @tracked entranceErrorCount = {};
21
- @tracked dwellingErrorCount = {};
22
-
23
- @tracked buildings = {};
24
19
 
25
20
  @lastValue("fetchProject") project;
26
21
  @restartableTask
@@ -34,34 +29,36 @@ export default class ProjectErrorsController extends Controller {
34
29
  return project;
35
30
  }
36
31
 
32
+ get workBuildings() {
33
+ return this.project.work
34
+ .filter((w) => !w.building.isNew)
35
+ .map((w) => w.building);
36
+ }
37
+
37
38
  @enqueueTask
38
39
  *fetchModel(buildingId) {
39
40
  // building response only contains entrances
40
- const building = yield this.building.getFromCacheOrApi(buildingId);
41
- this.buildingErrorCount = {
42
- ...this.buildingErrorCount,
43
- [buildingId]: building.errorList?.length ?? 0,
44
- };
41
+ const buildingWithErrors = yield this.building.getFromCacheOrApi(
42
+ buildingId
43
+ );
44
+ const buildingErrorCount = buildingWithErrors.errorList?.length ?? 0;
45
45
 
46
46
  // response contains both entrances and dwellings
47
47
  const projectBuilding = this.project.work.find(
48
48
  (buildingWork) => buildingWork.building.EGID === buildingId
49
49
  ).building;
50
50
 
51
- const entrances = yield Promise.all(
51
+ const entrancesWithErrors = yield Promise.all(
52
52
  projectBuilding.buildingEntrance.map((entrance) =>
53
53
  this.buildingEntrance.getFromCacheOrApi(entrance.EDID, buildingId)
54
54
  )
55
55
  );
56
56
 
57
- this.entranceErrorCount = {
58
- ...this.entranceErrorCount,
59
- [buildingId]: entrances
60
- .map((entrance) => entrance.errorList?.length ?? 0)
61
- .reduce((a, b) => a + b, 0),
62
- };
57
+ const entranceErrorCount = entrancesWithErrors
58
+ .map((entrance) => entrance.errorList?.length ?? 0)
59
+ .reduce((a, b) => a + b, 0);
63
60
 
64
- const dwellings = (yield Promise.all(
61
+ const dwellingsWithErrors = (yield Promise.all(
65
62
  projectBuilding.buildingEntrance.map((entrance) => {
66
63
  return Promise.all(
67
64
  entrance.dwelling.map((dwelling) =>
@@ -71,18 +68,17 @@ export default class ProjectErrorsController extends Controller {
71
68
  })
72
69
  )).flat();
73
70
 
74
- this.dwellingErrorCount = {
75
- ...this.dwellingErrorCount,
76
- [buildingId]: dwellings
77
- .map((dwelling) => dwelling.errorList?.length ?? 0)
78
- .reduce((a, b) => a + b, 0),
79
- };
71
+ const dwellingErrorCount = dwellingsWithErrors
72
+ .map((dwelling) => dwelling.dwelling.errorList?.length ?? 0)
73
+ .reduce((a, b) => a + b, 0);
80
74
 
81
- this.buildings = {
82
- ...this.buildings,
83
- [buildingId]: { building, entrances, dwellings },
75
+ return {
76
+ buildingWithErrors,
77
+ buildingErrorCount,
78
+ entrancesWithErrors,
79
+ entranceErrorCount,
80
+ dwellingsWithErrors,
81
+ dwellingErrorCount,
84
82
  };
85
-
86
- return building;
87
83
  }
88
84
  }