2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {get} from '@ember/object';
|
2016-08-17 18:01:46 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
|
2017-02-21 21:28:44 +03:00
|
|
|
themes: null,
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2017-03-03 18:31:42 +03:00
|
|
|
sortedThemes: computed('themes.@each.active', function () {
|
2017-02-21 21:28:44 +03:00
|
|
|
let themes = get(this, 'themes').map((t) => {
|
2016-08-17 18:01:46 +03:00
|
|
|
let theme = {};
|
2017-02-21 21:28:44 +03:00
|
|
|
let themePackage = get(t, 'package');
|
2016-08-17 18:01:46 +03:00
|
|
|
|
2017-03-03 18:31:42 +03:00
|
|
|
theme.model = t;
|
2017-02-21 21:28:44 +03:00
|
|
|
theme.name = get(t, 'name');
|
2017-02-27 09:31:01 +03:00
|
|
|
theme.label = themePackage ? `${themePackage.name}` : theme.name;
|
|
|
|
theme.version = themePackage ? `${themePackage.version}` : '1.0';
|
2017-02-21 21:28:44 +03:00
|
|
|
theme.package = themePackage;
|
2017-03-03 18:31:42 +03:00
|
|
|
theme.active = get(t, 'active');
|
2016-08-23 18:55:23 +03:00
|
|
|
theme.isDeletable = !theme.active;
|
2016-08-17 18:01:46 +03:00
|
|
|
|
|
|
|
return theme;
|
2016-08-23 18:55:23 +03:00
|
|
|
});
|
|
|
|
let duplicateThemes = [];
|
|
|
|
|
|
|
|
themes.forEach((theme) => {
|
|
|
|
let duplicateLabels = themes.filterBy('label', theme.label);
|
|
|
|
|
|
|
|
if (duplicateLabels.length > 1) {
|
|
|
|
duplicateThemes.pushObject(theme);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
duplicateThemes.forEach((theme) => {
|
|
|
|
if (theme.name !== 'casper') {
|
|
|
|
theme.label = `${theme.label} (${theme.name})`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// "(default)" needs to be added to casper manually as it's always
|
|
|
|
// displayed and would mess up the duplicate checking if added earlier
|
|
|
|
let casper = themes.findBy('name', 'casper');
|
|
|
|
if (casper) {
|
|
|
|
casper.label = `${casper.label} (default)`;
|
|
|
|
casper.isDefault = true;
|
|
|
|
casper.isDeletable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sorting manually because .sortBy('label') has a different sorting
|
|
|
|
// algorithm to [...strings].sort()
|
|
|
|
return themes.sort((themeA, themeB) => {
|
|
|
|
let a = themeA.label.toLowerCase();
|
|
|
|
let b = themeB.label.toLowerCase();
|
|
|
|
|
|
|
|
if (a < b) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a > b) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
2016-08-17 18:01:46 +03:00
|
|
|
}).readOnly()
|
|
|
|
|
|
|
|
});
|