ember-ebau-gwr 6.0.2 → 6.0.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 CHANGED
@@ -1,3 +1,12 @@
1
+ ## [6.0.3](https://github.com/adfinis-sygroup/ember-ebau-gwr/compare/v6.0.2...v6.0.3) (2022-09-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **import:** fix import functionality ([27da792](https://github.com/adfinis-sygroup/ember-ebau-gwr/commit/27da792438fe63b37e54cd6ff8d41f5816a8664c))
7
+ * **project:** don't rerender unnecessarily ([df737d5](https://github.com/adfinis-sygroup/ember-ebau-gwr/commit/df737d57ca5048574e684f1eac3705cc34f83c19))
8
+ * **projects:** handle refetching of projects for new projects ([192fddb](https://github.com/adfinis-sygroup/ember-ebau-gwr/commit/192fddb0b7325ececd8d95acfe0390c3d9576100))
9
+
1
10
  ## [6.0.2](https://github.com/adfinis-sygroup/ember-ebau-gwr/compare/v6.0.1...v6.0.2) (2022-09-21)
2
11
 
3
12
 
@@ -1,41 +1,40 @@
1
- {{#if this.import.isLoading}}
2
- <Loading />
3
- {{else}}
4
-
5
- {{#if this.import.error}}
6
- <div
7
- class={{if this.noImportData "uk-alert-warning" "uk-alert-error"}}
8
- uk-alert
9
- >
1
+ {{#if this.import.error}}
2
+ <div
3
+ class={{if this.noImportData "uk-alert-warning" "uk-alert-error"}}
4
+ uk-alert
5
+ >
10
6
 
11
- {{! The aria-label attr results in a template-lint error for some reason: error Cannot read properties of undefined (reading 'replace') undefined}}
12
- {{! template-lint-disable}}
13
- <a
14
- aria-label={{t "ember-gwr.close"}}
15
- class="uk-alert-close"
16
- href=""
17
- uk-close
18
- ></a>
19
- {{! template-lint-enable}}
20
- <p>
21
- {{#if this.noImportData}}
22
- {{t "ember-gwr.components.modelForm.noImportData"}}
23
- {{else}}
24
- {{t "ember-gwr.components.modelForm.importError"}}
25
- {{/if}}
26
- </p>
27
- </div>
28
- {{/if}}
7
+ {{! The aria-label attr results in a template-lint error for some reason: error Cannot read properties of undefined (reading 'replace') undefined}}
8
+ {{! template-lint-disable}}
9
+ <a
10
+ aria-label={{t "ember-gwr.close"}}
11
+ class="uk-alert-close"
12
+ href=""
13
+ uk-close
14
+ ></a>
15
+ {{! template-lint-enable}}
16
+ <p>
17
+ {{#if this.noImportData}}
18
+ {{t "ember-gwr.components.modelForm.noImportData"}}
19
+ {{else}}
20
+ {{t "ember-gwr.components.modelForm.importError"}}
21
+ {{/if}}
22
+ </p>
23
+ </div>
24
+ {{/if}}
29
25
 
30
- <ValidatedForm
31
- @model={{if @validations (changeset @model @validations) @model}}
32
- @on-submit={{perform this.submit}}
33
- @on-invalid-submit={{fn (mut this.invalidSubmit) true}}
34
- @validateBeforeSubmit={{true}}
35
- class="validated-form"
36
- ...attributes
37
- as |f|
38
- >
26
+ <ValidatedForm
27
+ @model={{if @validations (changeset @model @validations) @model}}
28
+ @on-submit={{perform this.submit}}
29
+ @on-invalid-submit={{fn (mut this.invalidSubmit) true}}
30
+ @validateBeforeSubmit={{true}}
31
+ class="validated-form"
32
+ ...attributes
33
+ as |f|
34
+ >
35
+ {{#if this.import.isLoading}}
36
+ <Loading />
37
+ {{else}}
39
38
  {{#let
40
39
  (component
41
40
  f.submit
@@ -111,5 +110,5 @@
111
110
  {{/if}}
112
111
  </div>
113
112
  {{/let}}
114
- </ValidatedForm>
115
- {{/if}}
113
+ {{/if}}
114
+ </ValidatedForm>
@@ -25,7 +25,7 @@ export default class ModelFormComponent extends Component {
25
25
  }));
26
26
 
27
27
  get importData() {
28
- const index = Number(this.args.importIndex);
28
+ const index = parseInt(this.args.importIndex);
29
29
  const data =
30
30
  Array.isArray(this.import.value) && !isNaN(index)
31
31
  ? this.import.value[index]
@@ -117,7 +117,7 @@ export default class ModelFormComponent extends Component {
117
117
  }
118
118
  });
119
119
  };
120
- deepMerge(this.args.model, this.import.value.data);
120
+ deepMerge(this.args.model, this.importData.data);
121
121
  this.finishImport();
122
122
  }
123
123
  }
@@ -110,6 +110,9 @@ export default class BuildingEditDwellingEditController extends ImportController
110
110
  );
111
111
  }
112
112
  }
113
+
114
+ this.resetImportQueryParams();
115
+
113
116
  // Ensure dwelling list is refreshed
114
117
  this.building.clearCache(this.model.buildingId);
115
118
  this.errors = [];
@@ -147,6 +147,9 @@ export default class BuildingFormController extends ImportController {
147
147
  // Clear cache so after transition we fetch the project form api
148
148
  this.constructionProject.clearCache(this.model.projectId);
149
149
  }
150
+
151
+ this.resetImportQueryParams();
152
+
150
153
  this.buildingAPI.clearCache(this.model.buildingId);
151
154
  this.errors = [];
152
155
  this.router.transitionTo("building.edit.form", EGID);
@@ -1,11 +1,12 @@
1
1
  import Controller from "@ember/controller";
2
+ import { registerDestructor } from "@ember/destroyable";
2
3
  import { inject as service } from "@ember/service";
3
- import { trackedFunction } from "ember-resources/util/function";
4
+ import { task, lastValue } from "ember-concurrency";
5
+ import { Resource } from "ember-resources";
4
6
 
5
7
  export default class ProjectController extends Controller {
6
8
  @service router;
7
9
  @service config;
8
- @service intl;
9
10
  @service constructionProject;
10
11
 
11
12
  get activeProjectId() {
@@ -24,30 +25,71 @@ export default class ProjectController extends Controller {
24
25
  );
25
26
  }
26
27
 
27
- projects = trackedFunction(this, async () => {
28
- // TrackedFunction only re-runs in case of changes in tracked properties
29
- // appearing before the first await / yield expression (which is necessary in this
30
- // case due to the infinite loop of fetching issue).
31
- // Related issue: https://github.com/NullVoxPopuli/ember-resources/issues/340
32
- const activeProjectId = this.activeProjectId;
33
- const model = this.model;
34
- await Promise.resolve();
35
-
36
- if (!model) {
37
- return [
38
- await this.constructionProject.getFromCacheOrApi(activeProjectId),
39
- ];
40
- }
28
+ projects = ProjectsResource.from(this, () => ({
29
+ model: this.model,
30
+ activeProjectId: this.activeProjectId,
31
+ }));
32
+ }
33
+
34
+ // The `ProjectController.activeProjectId` getter is computed even if
35
+ // `ProjectController.router.externalRouter.currentRoute` has changes
36
+ // in its query params and `ProjectController.activeProjectId` has not actually
37
+ // changed. This could be the case when all import fields are resolved
38
+ // and we transition form `?import=true` to `?import=false`.
39
+ //
40
+ // To prevent a rerender of the whole form (since if `ProjectController.isLoading` is true,
41
+ // we render a spinner) the `ProjectsResource.fetchProjects` task is only performed, if the
42
+ // `ProjectController.activeProjectId` has actually changed.
43
+ export class ProjectsResource extends Resource {
44
+ @service constructionProject;
45
+ @service router;
41
46
 
42
- // We then use `gwr.projects` in the template to reference this.
43
- // This is so we can update the table if we add a new project in the subroute /new
44
- const projects = await this.constructionProject.all.perform(model);
47
+ _lastActiveProjectId = null;
45
48
 
46
- // Load the first project in the list if none is selected so we always display a project.
47
- if (projects.length && this.router.currentRouteName === "project.index") {
48
- this.router.transitionTo("project.form", projects[0].EPROID);
49
+ constructor(owner) {
50
+ super(owner);
51
+
52
+ registerDestructor(this, () => {
53
+ this.fetchProjects.cancelAll({ resetState: true });
54
+ });
55
+ }
56
+
57
+ modify(_positional, named) {
58
+ // The task is only performed, if the `activeProjectId` has changed
59
+ // since the last run. String cast is used to catch NaN values, since NaN
60
+ // is not equal to NaN.
61
+ if (String(this._lastActiveProjectId) !== String(named.activeProjectId)) {
62
+ this.fetchProjects.perform(named);
63
+ this._lastActiveProjectId = named.activeProjectId;
49
64
  }
65
+ }
50
66
 
51
- return this.constructionProject.projects;
52
- });
67
+ get isLoading() {
68
+ return this.fetchProjects.isRunning;
69
+ }
70
+
71
+ @lastValue("fetchProjects") value;
72
+ @task
73
+ *fetchProjects({ model, activeProjectId }) {
74
+ try {
75
+ if (!model) {
76
+ return [
77
+ yield this.constructionProject.getFromCacheOrApi(activeProjectId),
78
+ ];
79
+ }
80
+
81
+ // We then use `gwr.projects` in the template to reference this.
82
+ // This is so we can update the table if we add a new project in the subroute /new
83
+ const projects = yield this.constructionProject.all.perform(model);
84
+
85
+ // Load the first project in the list if none is selected so we always display a project.
86
+ if (projects.length && this.router.currentRouteName === "project.index") {
87
+ this.router.transitionTo("project.form", projects[0].EPROID);
88
+ }
89
+
90
+ return this.constructionProject.projects;
91
+ } catch (error) {
92
+ console.error(error);
93
+ }
94
+ }
53
95
  }
@@ -43,8 +43,6 @@ export default class ImportResource extends Resource {
43
43
  @lastValue("fetchCalumaData") value;
44
44
  @task
45
45
  *fetchCalumaData({ instanceId, showImport, importModelName }) {
46
- this.error = null;
47
-
48
46
  if (instanceId && showImport) {
49
47
  assert(
50
48
  "Must set `importModelName` to a string.",
@@ -64,6 +62,7 @@ export default class ImportResource extends Resource {
64
62
  });
65
63
  this.error = NO_DATA_ERROR;
66
64
  } else {
65
+ this.error = null;
67
66
  return data?.length === 1 ? data[0] : data;
68
67
  }
69
68
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-ebau-gwr",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "description": "Ember engine to integrate ebau-gwr into an ember app.",
5
5
  "keywords": [
6
6
  "ember-addon",