mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
* chore: upgrade forward compatible packages * chore: v3.20.2...v3.24.0 * chore: silence string prototype extension deprecation * refact: don't test clicking disabled button job-list Recent test-helper upgrades will guard against clicking disabled buttons as this is not something that real users can do. We need to change our tests accordingly. * fix: await async test helper `expectError` We have to await this async test function otherwise the test's rendering context will be torn down before we run assertions against it. * fix: don't try to click disabled two-step-button Recent test-helper updates prohibit clicking disabled buttons. We need to adapt the tests accordingly. * fix: recommendation-accordion Use up-to-date semantics for handling list-accordion closing in recommendation-accordion. * fixes toggling recommendation-accordion toggle. * fix: simple-unless linting error application.hbs There's no reason to use unless here - we can use if instead. * fix: no-quoteless-attributes recommendation accordion * fix: no-quoteless-attributes recommendation-chart * fix: allow `unless` - global-header.hbs This is a valid use of unless in our opinion. * fix: allow unless in job-diff This is not a great use for unless but we don't want to change this behavior atm. * fix: no-attrs-in-components list-pager There is no need to use this.attrs in classic components. When we will convert to glimmer we will use `@`-instead. * fix: simple-unless job/definition We can convert to a simple if here. * fix: allow inline-styles stats-box component To make linter happy. * fix: disable no-action and no-invalid-interactive Will be adressed in follow-up PRs. * chore: update ember-classic-decorator to latest * chore: upgrade ember-can to latest * chore: upgrade ember-composable-helpers to latest * chore: upgrade ember-concurrency * fix: recomputation deprecation `Trigger` schedule `do` on actions queue to work around recomputation deprecation when triggering Trigger on `did-insert`. * chore: upgrade ember-cli-string-helpers * chore: upgrade ember-copy * chore: upgrade ember-data-model-fragments * chore: upgrade ember-deprecation-workflow * chore: upgrade ember-inline-svg * chore: upgrade ember-modifier * chore: upgrade ember-truth-helpers * chore: upgrade ember-moment & ember-cli-moment-shim * chore: upgrade ember-power-select * chore: upgrade ember-responsive * chore: upgrade ember-sinon * chore: upgrade ember-cli-mirage For now we will stay on 2.2 - upgrades > 2.3 break the build. * chore: upgrade 3.24.0 to 3.28.5 * fix: add missing classic decorators on adapters * fix: missing classic decorators to serializers * fix: don't reopen Ember.Object anymore * fix: remove unused useNativeEvents ember-cli-page-objects doesn't provide this method anymore * fix: add missing attributeBindings for test-selectors ember-test-selectors doesn't provides automatic bindings for data-test-* attributes anymore. * fix: classic decorator for application serializer test * fix: remove `removeContext` from tests. It is unneeded and ember-cli-page-objects doesn't provides this method anymore. * fix: remove deprecations `run.*`-invocations * fix: `collapseWhitespace` in optimize test * fix: make sure to load async relationship before access * fix: dependent keys for relationship computeds We need to add `*.isFulfilled` as dependent keys for computeds that access async relationships. * fix: `computed.read`-invocations use `read` instead * chore: prettify templates * fix: use map instead of mapBy ember-cli-page-object Doesn't work with updated ember-cli-page-object anymore. * fix: remove remaining deprecated `run.*`-calls * chore: add more deprecations deprecation-workflow * fix: `implicit-injection`-deprecation All routes that add watchers will need to inject the store-service as the store service is internally used in watchers. * fix: more implicit injection deprecations * chore: silence implicit-injection deprecation We can tackle the deprecation when we find the time. * fix: new linting errors after upgrade * fix: remove merge conflicts prettierignore * chore: upgrade to run node 12.22 when building binaries
182 lines
5.1 KiB
JavaScript
182 lines
5.1 KiB
JavaScript
/* eslint-disable ember/no-string-prototype-extensions */
|
|
import { copy } from 'ember-copy';
|
|
import { get } from '@ember/object';
|
|
import { makeArray } from '@ember/array';
|
|
import JSONSerializer from '@ember-data/serializer/json';
|
|
import { pluralize, singularize } from 'ember-inflector';
|
|
import removeRecord from '../utils/remove-record';
|
|
import { assign } from '@ember/polyfills';
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
@classic
|
|
export default class Application extends JSONSerializer {
|
|
primaryKey = 'ID';
|
|
|
|
/**
|
|
A list of keys that are converted to empty arrays if their value is null.
|
|
|
|
arrayNullOverrides = ['Array'];
|
|
{ Array: null } => { Array: [] }
|
|
|
|
@property arrayNullOverrides
|
|
@type String[]
|
|
*/
|
|
arrayNullOverrides = null;
|
|
|
|
/**
|
|
A list of keys that are converted to empty objects if their value is null.
|
|
|
|
objectNullOverrides = ['Object'];
|
|
{ Object: null } => { Object: {} }
|
|
|
|
@property objectNullOverrides
|
|
@type String[]
|
|
*/
|
|
objectNullOverrides = null;
|
|
|
|
/**
|
|
A list of keys or objects to convert a map into an array of maps with the original map keys as Name properties.
|
|
|
|
mapToArray = ['Map'];
|
|
{ Map: { a: { x: 1 } } } => { Map: [ { Name: 'a', x: 1 }] }
|
|
|
|
mapToArray = [{ beforeName: 'M', afterName: 'Map' }];
|
|
{ M: { a: { x: 1 } } } => { Map: [ { Name: 'a', x: 1 }] }
|
|
|
|
@property mapToArray
|
|
@type (String|Object)[]
|
|
*/
|
|
mapToArray = null;
|
|
|
|
/**
|
|
A list of keys for nanosecond timestamps that will be split into two properties: `separateNanos = ['Time']` will
|
|
produce a `Time` property with a millisecond timestamp and `TimeNanos` with the nanoseconds alone.
|
|
|
|
separateNanos = ['Time'];
|
|
{ Time: 1607839992000100000 } => { Time: 1607839992000, TimeNanos: 100096 }
|
|
|
|
@property separateNanos
|
|
@type String[]
|
|
*/
|
|
separateNanos = null;
|
|
|
|
keyForAttribute(attr) {
|
|
return attr.camelize().capitalize();
|
|
}
|
|
|
|
keyForRelationship(attr, relationshipType) {
|
|
const key = `${singularize(attr).camelize().capitalize()}ID`;
|
|
return relationshipType === 'hasMany' ? pluralize(key) : key;
|
|
}
|
|
|
|
// Modeled after the pushPayload for ember-data/serializers/rest
|
|
pushPayload(store, payload) {
|
|
const documentHash = {
|
|
data: [],
|
|
included: [],
|
|
};
|
|
|
|
Object.keys(payload).forEach((key) => {
|
|
const modelName = this.modelNameFromPayloadKey(key);
|
|
const serializer = store.serializerFor(modelName);
|
|
const type = store.modelFor(modelName);
|
|
|
|
makeArray(payload[key]).forEach((hash) => {
|
|
const { data, included } = serializer.normalize(type, hash, key);
|
|
documentHash.data.push(data);
|
|
if (included) {
|
|
documentHash.included.push(...included);
|
|
}
|
|
});
|
|
});
|
|
|
|
store.push(documentHash);
|
|
}
|
|
|
|
normalize(modelClass, hash) {
|
|
if (hash) {
|
|
if (this.arrayNullOverrides) {
|
|
this.arrayNullOverrides.forEach((key) => {
|
|
if (!hash[key]) {
|
|
hash[key] = [];
|
|
}
|
|
});
|
|
}
|
|
if (this.objectNullOverrides) {
|
|
this.objectNullOverrides.forEach((key) => {
|
|
if (!hash[key]) {
|
|
hash[key] = {};
|
|
}
|
|
});
|
|
}
|
|
|
|
if (this.mapToArray) {
|
|
this.mapToArray.forEach((conversion) => {
|
|
let apiKey, uiKey;
|
|
|
|
if (conversion.beforeName) {
|
|
apiKey = conversion.beforeName;
|
|
uiKey = conversion.afterName;
|
|
} else {
|
|
apiKey = conversion;
|
|
uiKey = conversion;
|
|
}
|
|
|
|
const map = hash[apiKey] || {};
|
|
|
|
hash[uiKey] = Object.keys(map)
|
|
.sort()
|
|
.map((mapKey) => {
|
|
const propertiesForKey = map[mapKey] || {};
|
|
const convertedMap = { Name: mapKey };
|
|
|
|
assign(convertedMap, propertiesForKey);
|
|
|
|
return convertedMap;
|
|
});
|
|
});
|
|
}
|
|
|
|
if (this.separateNanos) {
|
|
this.separateNanos.forEach((key) => {
|
|
const timeWithNanos = hash[key];
|
|
hash[`${key}Nanos`] = timeWithNanos % 1000000;
|
|
hash[key] = Math.floor(timeWithNanos / 1000000);
|
|
});
|
|
}
|
|
}
|
|
|
|
return super.normalize(modelClass, hash);
|
|
}
|
|
|
|
normalizeFindAllResponse(store, modelClass) {
|
|
const result = super.normalizeFindAllResponse(...arguments);
|
|
this.cullStore(store, modelClass.modelName, result.data);
|
|
return result;
|
|
}
|
|
|
|
// When records are removed server-side, and therefore don't show up in requests,
|
|
// the local copies of those records need to be unloaded from the store.
|
|
cullStore(store, type, records, storeFilter = () => true) {
|
|
const newRecords = copy(records).filter((record) => get(record, 'id'));
|
|
const oldRecords = store.peekAll(type);
|
|
oldRecords
|
|
.filter((record) => get(record, 'id'))
|
|
.filter(storeFilter)
|
|
.forEach((old) => {
|
|
const newRecord = newRecords.find(
|
|
(record) => get(record, 'id') === get(old, 'id')
|
|
);
|
|
if (!newRecord) {
|
|
removeRecord(store, old);
|
|
} else {
|
|
newRecords.removeObject(newRecord);
|
|
}
|
|
});
|
|
}
|
|
|
|
modelNameFromPayloadKey(key) {
|
|
return singularize(key.dasherize());
|
|
}
|
|
}
|