@projectcaluma/ember-core 10.1.0 → 11.0.0-beta.24

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.
@@ -1,44 +1,31 @@
1
1
  export default {
2
- Node: [
3
- "Workflow",
4
- "Form",
5
- "Document",
6
- "Case",
7
- "WorkItem",
8
- "Flow",
9
- "DynamicOption",
10
- "Option",
2
+ Question: [
11
3
  "TextQuestion",
12
- "StringAnswer",
13
4
  "ChoiceQuestion",
14
5
  "MultipleChoiceQuestion",
15
- "ListAnswer",
16
6
  "DynamicChoiceQuestion",
17
7
  "DynamicMultipleChoiceQuestion",
18
8
  "TextareaQuestion",
19
9
  "FloatQuestion",
20
- "FloatAnswer",
21
10
  "IntegerQuestion",
22
- "IntegerAnswer",
23
11
  "DateQuestion",
24
- "DateAnswer",
25
12
  "TableQuestion",
26
- "TableAnswer",
27
13
  "FormQuestion",
28
- "FileQuestion",
14
+ "FilesQuestion",
29
15
  "StaticQuestion",
30
- "FileAnswer",
31
- "File",
32
16
  "CalculatedFloatQuestion",
33
17
  "ActionButtonQuestion",
34
- "SimpleTask",
35
- "CompleteWorkflowFormTask",
36
- "CompleteTaskFormTask",
37
18
  ],
38
- Task: ["SimpleTask", "CompleteWorkflowFormTask", "CompleteTaskFormTask"],
39
- Question: [
19
+ Node: [
40
20
  "TextQuestion",
21
+ "Form",
22
+ "Document",
23
+ "Case",
24
+ "Workflow",
25
+ "Flow",
26
+ "WorkItem",
41
27
  "ChoiceQuestion",
28
+ "Option",
42
29
  "MultipleChoiceQuestion",
43
30
  "DynamicChoiceQuestion",
44
31
  "DynamicMultipleChoiceQuestion",
@@ -48,19 +35,35 @@ export default {
48
35
  "DateQuestion",
49
36
  "TableQuestion",
50
37
  "FormQuestion",
51
- "FileQuestion",
38
+ "FilesQuestion",
52
39
  "StaticQuestion",
40
+ "StringAnswer",
41
+ "ListAnswer",
42
+ "IntegerAnswer",
43
+ "FloatAnswer",
44
+ "DateAnswer",
45
+ "TableAnswer",
46
+ "FilesAnswer",
47
+ "File",
53
48
  "CalculatedFloatQuestion",
54
49
  "ActionButtonQuestion",
50
+ "SimpleTask",
51
+ "CompleteWorkflowFormTask",
52
+ "CompleteTaskFormTask",
53
+ "AnalyticsTable",
54
+ "AvailableField",
55
+ "AnalyticsField",
56
+ "DynamicOption",
55
57
  ],
56
58
  Answer: [
57
59
  "StringAnswer",
58
60
  "ListAnswer",
59
- "FloatAnswer",
60
61
  "IntegerAnswer",
62
+ "FloatAnswer",
61
63
  "DateAnswer",
62
64
  "TableAnswer",
63
- "FileAnswer",
65
+ "FilesAnswer",
64
66
  ],
67
+ Task: ["SimpleTask", "CompleteWorkflowFormTask", "CompleteTaskFormTask"],
65
68
  DynamicQuestion: ["DynamicChoiceQuestion", "DynamicMultipleChoiceQuestion"],
66
69
  };
@@ -1,5 +1,11 @@
1
1
  import { getOwner, setOwner } from "@ember/application";
2
2
 
3
+ import CalumaQueryResource from "@projectcaluma/ember-core/caluma-query/resource";
4
+
5
+ export function useCalumaQuery(destroyable, query, thunk) {
6
+ return CalumaQueryResource.from(destroyable, () => ({ query, ...thunk() }));
7
+ }
8
+
3
9
  export default function calumaQuery({ query, options = {} }) {
4
10
  return function (_, name) {
5
11
  const privateKey = `__${name}`;
@@ -1,15 +1,15 @@
1
1
  import { inject as service } from "@ember/service";
2
2
 
3
3
  import CalumaQueryModel, {
4
- momentAttr,
4
+ dateAttr,
5
5
  } from "@projectcaluma/ember-core/caluma-query/models/index";
6
6
 
7
7
  export default class CaseModel extends CalumaQueryModel {
8
8
  @service intl;
9
9
 
10
- @momentAttr createdAt;
11
- @momentAttr modifiedAt;
12
- @momentAttr closedAt;
10
+ @dateAttr createdAt;
11
+ @dateAttr modifiedAt;
12
+ @dateAttr closedAt;
13
13
 
14
14
  get status() {
15
15
  return this.intl.t(`caluma.caluma-query.case.status.${this.raw.status}`);
@@ -1,5 +1,4 @@
1
1
  import cloneDeep from "lodash.clonedeep";
2
- import moment from "moment";
3
2
 
4
3
  import { decodeId } from "@projectcaluma/ember-core/helpers/decode-id";
5
4
 
@@ -11,15 +10,16 @@ export function uuidAttr(target, name) {
11
10
  };
12
11
  }
13
12
 
14
- export function momentAttr(target, name) {
13
+ export function dateAttr(target, name) {
15
14
  return {
16
15
  get() {
17
- const date = moment(this.raw[name]);
16
+ const raw = this.raw[name];
17
+ const date = raw ? new Date(raw) : null;
18
18
 
19
- return date.isValid() ? date : null;
19
+ return raw && !isNaN(date) ? date : null;
20
20
  },
21
21
  set(value) {
22
- if (value.isValid()) {
22
+ if (!isNaN(value)) {
23
23
  this.raw[name] = value.toISOString();
24
24
  }
25
25
  },
@@ -1,16 +1,16 @@
1
1
  import { inject as service } from "@ember/service";
2
2
 
3
3
  import CalumaQueryModel, {
4
- momentAttr,
4
+ dateAttr,
5
5
  } from "@projectcaluma/ember-core/caluma-query/models/index";
6
6
 
7
7
  export default class WorkItemModel extends CalumaQueryModel {
8
8
  @service intl;
9
9
 
10
- @momentAttr createdAt;
11
- @momentAttr modifiedAt;
12
- @momentAttr closedAt;
13
- @momentAttr deadline;
10
+ @dateAttr createdAt;
11
+ @dateAttr modifiedAt;
12
+ @dateAttr closedAt;
13
+ @dateAttr deadline;
14
14
 
15
15
  get status() {
16
16
  return this.intl.t(
@@ -7,7 +7,7 @@ import {
7
7
  lastValue,
8
8
  restartableTask,
9
9
  task,
10
- } from "ember-concurrency-decorators";
10
+ } from "ember-concurrency";
11
11
  import { gql } from "graphql-tag";
12
12
 
13
13
  export default class BaseQuery {
@@ -0,0 +1,72 @@
1
+ import { getOwner, setOwner } from "@ember/application";
2
+ import { destroy, registerDestructor } from "@ember/destroyable";
3
+ import { action } from "@ember/object";
4
+ import { tracked } from "@glimmer/tracking";
5
+ import { Resource } from "ember-resources/core";
6
+
7
+ const MUTABLE_OPTIONS = [
8
+ "pageSize",
9
+ "processAll",
10
+ "processNew",
11
+ "queryOptions",
12
+ ];
13
+
14
+ export default class CalumaQueryResource extends Resource {
15
+ @tracked query;
16
+
17
+ didSetup = false;
18
+
19
+ constructor(owner, args) {
20
+ super(owner, args);
21
+
22
+ registerDestructor(this, () => {
23
+ destroy(this.query);
24
+ });
25
+ }
26
+
27
+ modify(_, { options = {}, query, ...args }) {
28
+ if (!this.didSetup) {
29
+ // initialize the caluma query with the given options
30
+ this.query = query(options);
31
+ setOwner(this.query, getOwner(this));
32
+
33
+ this.didSetup = true;
34
+ } else {
35
+ // update changed options on the caluma query
36
+ MUTABLE_OPTIONS.forEach((optionKey) => {
37
+ const option = options[optionKey];
38
+
39
+ if (option !== undefined && option !== this.query[optionKey]) {
40
+ this.query[optionKey] = option;
41
+ }
42
+ });
43
+ }
44
+
45
+ this.query.fetch(args);
46
+ }
47
+
48
+ @action
49
+ fetchMore(event) {
50
+ if (event instanceof Event) {
51
+ event.preventDefault();
52
+ }
53
+
54
+ this.query.fetchMore();
55
+ }
56
+
57
+ get value() {
58
+ return this.query.value;
59
+ }
60
+
61
+ get hasNextPage() {
62
+ return this.query.hasNextPage;
63
+ }
64
+
65
+ get totalCount() {
66
+ return this.query.totalCount;
67
+ }
68
+
69
+ get isLoading() {
70
+ return this.query.isLoading;
71
+ }
72
+ }
@@ -7,7 +7,9 @@ import { dasherize } from "@ember/string";
7
7
  const parse = (raw) => dasherize(raw.replace("Question", ""));
8
8
 
9
9
  export function hasQuestionType(obj, ...expected) {
10
- return expected.map(parse).includes(parse(obj?.__typename || ""));
10
+ return expected
11
+ .map(parse)
12
+ .includes(parse((obj?.raw?.__typename ?? obj?.__typename) || ""));
11
13
  }
12
14
 
13
15
  export default helper(([obj, ...expected]) =>
@@ -2,6 +2,7 @@ import { assert } from "@ember/debug";
2
2
  import { once } from "@ember/runloop";
3
3
  import Service, { inject as service } from "@ember/service";
4
4
  import { camelize } from "@ember/string";
5
+ import { tracked } from "@glimmer/tracking";
5
6
  import { task } from "ember-concurrency";
6
7
  import { pluralize } from "ember-inflector";
7
8
 
@@ -14,25 +15,46 @@ import { pluralize } from "ember-inflector";
14
15
  */
15
16
  function typeResolver(type) {
16
17
  return task(function* () {
17
- const identifiers = [...this[type].identifiers];
18
- const callbacks = [...this[type].callbacks];
18
+ const identifiers = [...(this[type]?.identifiers ?? [])];
19
+ const callbacks = [...(this[type]?.callbacks ?? [])];
19
20
 
20
21
  this[type] = undefined;
21
22
 
22
23
  if (!identifiers.length) return;
23
24
 
25
+ const cached = this[`${type}Cache`];
26
+ const uncachedIdentifiers = identifiers.filter(
27
+ (identifier) =>
28
+ !cached
29
+ .map((resolved) =>
30
+ String(resolved[this.calumaOptions[`${type}IdentifierProperty`]])
31
+ )
32
+ .includes(String(identifier))
33
+ );
34
+
24
35
  const methodName = camelize(`resolve-${pluralize(type)}`);
25
- const result = yield this.calumaOptions[methodName]?.(identifiers);
36
+ const result = uncachedIdentifiers.length
37
+ ? yield this.calumaOptions[methodName]?.(uncachedIdentifiers)
38
+ : [];
39
+
40
+ const allResults = [...cached, ...(result?.toArray?.() ?? result ?? [])];
26
41
 
27
- yield Promise.all(callbacks.map((callback) => callback(result)));
42
+ if (result?.length) {
43
+ this[`${type}Cache`] = allResults;
44
+ }
45
+
46
+ yield Promise.all(callbacks.map((callback) => callback(allResults)));
28
47
 
29
- return result;
48
+ return allResults;
30
49
  }).enqueue();
31
50
  }
32
51
 
33
52
  export default class PrivateSchedulerService extends Service {
34
53
  @service calumaOptions;
35
54
 
55
+ @tracked groupCache = [];
56
+ @tracked userCache = [];
57
+
36
58
  @typeResolver("group") resolveGroup;
37
59
  @typeResolver("user") resolveUser;
38
60
 
@@ -1,12 +1,12 @@
1
1
  import { InMemoryCache, defaultDataIdFromObject } from "@apollo/client/cache";
2
2
  import { setContext } from "@apollo/client/link/context";
3
- import Mixin from "@ember/object/mixin";
4
3
  import { inject as service } from "@ember/service";
4
+ import ApolloService from "ember-apollo-client/services/apollo";
5
5
 
6
6
  import possibleTypes from "@projectcaluma/ember-core/-private/possible-types";
7
7
 
8
- export default Mixin.create({
9
- intl: service(),
8
+ export default class CalumaApolloService extends ApolloService {
9
+ @service intl;
10
10
 
11
11
  cache() {
12
12
  return new InMemoryCache({
@@ -17,10 +17,10 @@ export default Mixin.create({
17
17
  _id: obj.slug || obj._id,
18
18
  }),
19
19
  });
20
- },
20
+ }
21
21
 
22
- link(...args) {
23
- const httpLink = this._super(...args);
22
+ link() {
23
+ const httpLink = super.link();
24
24
 
25
25
  const localeLink = setContext((request, context) => ({
26
26
  ...context,
@@ -32,5 +32,5 @@ export default Mixin.create({
32
32
  }));
33
33
 
34
34
  return localeLink.concat(httpLink);
35
- },
36
- });
35
+ }
36
+ }
@@ -1,3 +1,4 @@
1
+ import { assert } from "@ember/debug";
1
2
  import Service, { inject as service } from "@ember/service";
2
3
  import { tracked } from "@glimmer/tracking";
3
4
 
@@ -17,33 +18,6 @@ export default class CalumaOptionsService extends Service {
17
18
 
18
19
  @tracked currentGroupId;
19
20
 
20
- constructor(...args) {
21
- super(...args);
22
-
23
- this.registerComponentOverride({
24
- label: this.intl.t(
25
- "caluma.form-builder.question.widgetOverrides.powerselect"
26
- ),
27
- component: "cf-field/input/powerselect",
28
- types: [
29
- "ChoiceQuestion",
30
- "MultipleChoiceQuestion",
31
- "DynamicChoiceQuestion",
32
- "DynamicMultipleChoiceQuestion",
33
- ],
34
- });
35
-
36
- this.registerComponentOverride({
37
- label: this.intl.t("caluma.form-builder.question.widgetOverrides.hidden"),
38
- component: "cf-field/input/hidden",
39
- });
40
-
41
- this.registerComponentOverride({
42
- component: "cfb-form-editor/question/default/table",
43
- types: [],
44
- });
45
- }
46
-
47
21
  _namespace = null;
48
22
  _overrides = {};
49
23
 
@@ -109,4 +83,10 @@ export default class CalumaOptionsService extends Service {
109
83
  [this.userNameProperty]: identifier,
110
84
  }));
111
85
  }
86
+
87
+ fetchTypedGroups(/* types, search */) {
88
+ assert(
89
+ "`fetchTypedGroups` must be implemented on the Caluma options service"
90
+ );
91
+ }
112
92
  }
@@ -7,6 +7,6 @@ export default function (value, { locale = null } = {}) {
7
7
  return slugify(value, {
8
8
  lower: true,
9
9
  strict: true,
10
- locale,
10
+ locale: locale?.split("-")[0].toLowerCase(),
11
11
  }).substr(0, 127);
12
12
  }
@@ -0,0 +1 @@
1
+ export { default } from "@projectcaluma/ember-core/services/apollo";
@@ -0,0 +1 @@
1
+ @import "../cc-uikit-powerselect";
@@ -0,0 +1,31 @@
1
+ @import "ember-uikit/variables-theme";
2
+
3
+ // Backgrounds
4
+ $ember-power-select-selected-background: lighten(
5
+ $global-secondary-background,
6
+ 25%
7
+ ) !default;
8
+ $ember-power-select-highlighted-background: lighten(
9
+ $ember-power-select-selected-background,
10
+ 25%
11
+ ) !default;
12
+ $ember-power-select-multiple-selection-background-color: $ember-power-select-selected-background !default;
13
+
14
+ // Texts
15
+ $ember-power-select-highlighted-color: #ffffff !default;
16
+ $ember-power-select-multiple-selection-color: #ffffff !default;
17
+
18
+ .ember-power-select-option[aria-selected="true"] {
19
+ color: $ember-power-select-highlighted-color;
20
+ }
21
+
22
+ // Borders
23
+ $ember-power-select-focus-outline: 0 !default;
24
+ $ember-power-select-border-color: $global-border !default;
25
+ $ember-power-select-default-border-radius: 0 !default;
26
+ $ember-power-select-multiple-option-border-color: $ember-power-select-border-color !default;
27
+
28
+ // Other
29
+ $ember-power-select-line-height: 38px !default;
30
+ $ember-power-select-multiple-option-padding: 0 8px !default;
31
+ $ember-power-select-multiple-option-line-height: 32px !default;
@@ -0,0 +1 @@
1
+ export { default } from "@projectcaluma/ember-core/utils/jexl";
@@ -10,6 +10,6 @@ module.exports = {
10
10
  { name: "ember-intl" },
11
11
  { name: "ember-uikit" },
12
12
  ],
13
- }).then(() => this.addPackagesToProject([{ name: "moment" }]));
13
+ });
14
14
  },
15
15
  };
package/index.js CHANGED
@@ -1,30 +1,5 @@
1
1
  "use strict";
2
2
 
3
- const DEFAULT_OPTIONS = {
4
- includeProxyPolyfill: true,
5
- includeIntersectionObserverPolyfill: true,
6
- };
7
-
8
3
  module.exports = {
9
- name: require("./package").name,
10
-
11
- _getOptions() {
12
- const app = this._findHost();
13
-
14
- return Object.assign({}, DEFAULT_OPTIONS, app.options["ember-caluma"]);
15
- },
16
-
17
- included(...args) {
18
- this._super.included.apply(this, args);
19
-
20
- if (this._getOptions().includeProxyPolyfill) {
21
- this.import("node_modules/proxy-polyfill/proxy.min.js");
22
- }
23
-
24
- if (this._getOptions().includeIntersectionObserverPolyfill) {
25
- this.import(
26
- "node_modules/intersection-observer/intersection-observer.js"
27
- );
28
- }
29
- },
4
+ name: require("./package.json").name,
30
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-core",
3
- "version": "10.1.0",
3
+ "version": "11.0.0-beta.24",
4
4
  "description": "Ember core addon for working with Caluma.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -14,40 +14,40 @@
14
14
  "test:ember-compatibility": "ember try:each"
15
15
  },
16
16
  "dependencies": {
17
- "@apollo/client": "^3.5.6",
18
- "@glimmer/tracking": "^1.0.4",
19
- "ember-apollo-client": "^3.2.0",
20
- "ember-auto-import": "^2.2.3",
21
- "ember-changeset-validations": "^3.16.0",
22
- "ember-cli-babel": "^7.26.6",
23
- "ember-cli-htmlbars": "^6.0.1",
24
- "ember-concurrency": "^2.2.0",
25
- "ember-concurrency-decorators": "^2.0.3",
26
- "ember-fetch": "^8.0.4",
17
+ "@apollo/client": "^3.6.9",
18
+ "@ember/string": "^3.0.0",
19
+ "@glimmer/tracking": "^1.1.2",
20
+ "ember-apollo-client": "~4.0.2",
21
+ "ember-auto-import": "^2.4.2",
22
+ "ember-cli-babel": "^7.26.11",
23
+ "ember-cli-htmlbars": "^6.1.0",
24
+ "ember-concurrency": "^2.3.2",
25
+ "ember-fetch": "^8.1.2",
27
26
  "ember-inflector": "^4.0.2",
28
- "ember-intl": "^5.7.0",
29
- "graphql": "^15.6.1",
27
+ "ember-intl": "^5.7.2",
28
+ "ember-resources": "^5.2.1",
29
+ "ember-uikit": "^5.1.3",
30
+ "graphql": "^15.8.0",
30
31
  "graphql-tag": "^2.12.6",
31
- "intersection-observer": "^0.12.0",
32
32
  "jexl": "^2.3.0",
33
33
  "lodash.clonedeep": "^4.5.0",
34
- "moment": "^2.29.1",
35
- "proxy-polyfill": "^0.3.2",
36
- "slugify": "^1.6.3"
34
+ "slugify": "^1.6.5"
37
35
  },
38
36
  "devDependencies": {
39
37
  "@ember/optional-features": "2.0.0",
40
- "@ember/render-modifiers": "2.0.2",
41
- "@ember/test-helpers": "2.6.0",
42
- "@embroider/test-setup": "0.48.1",
43
- "@glimmer/component": "1.0.4",
44
- "@projectcaluma/ember-testing": "10.0.0",
38
+ "@ember/render-modifiers": "2.0.4",
39
+ "@ember/test-helpers": "2.8.1",
40
+ "@embroider/test-setup": "1.8.3",
41
+ "@embroider/util": "^1.8.3",
42
+ "@faker-js/faker": "7.4.0",
43
+ "@glimmer/component": "1.1.2",
44
+ "@projectcaluma/ember-testing": "11.0.0-beta.24",
45
45
  "broccoli-asset-rev": "3.0.0",
46
- "ember-cli": "3.28.4",
46
+ "ember-cli": "3.28.5",
47
47
  "ember-cli-code-coverage": "1.0.3",
48
- "ember-cli-dependency-checker": "3.2.0",
48
+ "ember-cli-dependency-checker": "3.3.1",
49
49
  "ember-cli-inject-live-reload": "2.1.0",
50
- "ember-cli-mirage": "2.2.0",
50
+ "ember-cli-mirage": "3.0.0-alpha.3",
51
51
  "ember-cli-sri": "2.1.1",
52
52
  "ember-cli-terser": "4.0.2",
53
53
  "ember-disable-prototype-extensions": "1.1.3",
@@ -56,15 +56,14 @@
56
56
  "ember-maybe-import-regenerator": "1.0.0",
57
57
  "ember-qunit": "5.1.5",
58
58
  "ember-resolver": "8.0.3",
59
- "ember-source": "3.28.8",
59
+ "ember-source": "3.28.9",
60
60
  "ember-source-channel-url": "3.0.0",
61
61
  "ember-try": "2.0.0",
62
- "faker": "5.5.3",
63
62
  "loader.js": "4.7.0",
64
63
  "npm-run-all": "4.1.5",
65
- "qunit": "2.17.2",
64
+ "qunit": "2.19.1",
66
65
  "qunit-dom": "2.0.0",
67
- "webpack": "5.65.0"
66
+ "webpack": "5.74.0"
68
67
  },
69
68
  "engines": {
70
69
  "node": "12.* || 14.* || >= 16"
@@ -73,6 +72,7 @@
73
72
  "edition": "octane"
74
73
  },
75
74
  "ember-addon": {
76
- "configPath": "tests/dummy/config"
75
+ "configPath": "tests/dummy/config",
76
+ "after": "ember-apollo-client"
77
77
  }
78
78
  }
@@ -1,12 +0,0 @@
1
- query AllFormatValidators {
2
- allFormatValidators {
3
- edges {
4
- node {
5
- slug
6
- name
7
- regex
8
- errorMsg
9
- }
10
- }
11
- }
12
- }
@@ -1,50 +0,0 @@
1
- import Helper from "@ember/component/helper";
2
- import { warn } from "@ember/debug";
3
- import { inject as service } from "@ember/service";
4
-
5
- /**
6
- * Helper for getting the right widget.
7
- *
8
- * This helper expects n objects as positional parameters. It checks if the
9
- * object has a widget override in it's metadata. If one exists it checks if
10
- * said widget was registered in the caluma options service and then returns
11
- * the widget name. If it doesn't have a valid widget, the next object will be
12
- * checked. If no object returns a valid widget, the passed default widget will
13
- * be used.
14
- *
15
- * ```hbs
16
- * {{component (get-widget field.question someobject default="cf-form") foo=bar}}
17
- * ```
18
- *
19
- * @function getWidget
20
- * @param {Array} params
21
- * @param {Object} [options]
22
- * @param {String} [options.default]
23
- */
24
- export default class GetWidgetHelper extends Helper {
25
- @service calumaOptions;
26
-
27
- compute(params, { default: defaultWidget = "cf-field/input" }) {
28
- for (const obj of params) {
29
- const widget = obj?.meta?.widgetOverride;
30
- if (!widget) {
31
- continue;
32
- }
33
- const override =
34
- widget &&
35
- this.calumaOptions
36
- .getComponentOverrides()
37
- .find(({ component }) => component === widget);
38
-
39
- warn(
40
- `Widget override "${widget}" is not registered. Please register it by calling \`calumaOptions.registerComponentOverride\``,
41
- override,
42
- { id: "ember-caluma.unregistered-override" }
43
- );
44
-
45
- if (override) return widget;
46
- }
47
-
48
- return defaultWidget;
49
- }
50
- }