-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathproject-version.js
131 lines (108 loc) · 3.73 KB
/
project-version.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* eslint-disable ember/no-computed-properties-in-native-classes, prettier/prettier */
import { action, computed, set } from '@ember/object';
import { inject as service } from '@ember/service';
import { readOnly, alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { A } from '@ember/array';
import values from 'lodash.values';
import groupBy from 'lodash.groupby';
import semverCompare from 'semver-compare';
import getCompactVersion from '../utils/get-compact-version';
export default class ProjectVersionController extends Controller {
@service
filterData;
@service
metaStore;
@service
project;
@alias('filterData.sideNav.showPrivate')
showPrivateClasses;
@computed('model')
get classesIDs() {
return this.getRelationshipIDs('classes');
}
@computed('model')
get publicClassesIDs() {
return this.getRelationshipIDs('public-classes');
}
@computed('model')
get namespaceIDs() {
return this.getRelationshipIDs('namespaces');
}
@computed('model')
get publicNamespaceIDs() {
return this.getRelationshipIDs('public-namespaces');
}
@computed('model.id')
get moduleIDs() {
return this.getModuleRelationships(this.model.id, 'modules');
}
@computed('model.id')
get publicModuleIDs() {
return this.getModuleRelationships(this.model.id, 'public-modules');
}
getModuleRelationships(versionId, moduleType) {
let relations = this.getRelations(moduleType);
// filter overviews out. If other projects add their overview we should filter those too.
return relations
.map((id) => id.substring(versionId.length + 1))
.filter((id) => id !== 'ember-data-overview');
}
getRelations(relationship) {
return this.model.hasMany(relationship).ids().sort();
}
getRelationshipIDs(relationship) {
// eslint-disable-next-line
const splitPoint = 2 + this.get('model.project.id').split('-').length - 1;
const classes = this.model.hasMany(relationship);
const sorted = A(classes.ids()).sort();
//ids come in as ember-2.16.0-@ember/object/promise-proxy-mixin
//so we take the string after the 2nd '-'
return A(sorted)
.toArray()
.map((id) => id.split('-').slice(splitPoint).join('-'));
}
@computed('showPrivateClasses', 'classesIDs', 'publicClassesIDs')
get shownClassesIDs() {
return this.showPrivateClasses ? this.classesIDs : this.publicClassesIDs;
}
@computed('showPrivateClasses', 'moduleIDs', 'publicModuleIDs')
get shownModuleIDs() {
return this.showPrivateClasses ? this.moduleIDs : this.publicModuleIDs;
}
@computed('showPrivateClasses', 'namespaceIDs', 'publicNamespaceIDs')
get shownNamespaceIDs() {
return this.showPrivateClasses
? this.namespaceIDs
: this.publicNamespaceIDs;
}
@computed('metaStore.availableProjectVersions', 'model.project.id')
get projectVersions() {
const projectVersions =
this.metaStore.availableProjectVersions[
this.model.belongsTo('project').id()
];
let versions = projectVersions.sort((a, b) => semverCompare(b, a));
versions = versions.map((version) => {
const compactVersion = getCompactVersion(version);
return { id: version, compactVersion };
});
let groupedVersions = groupBy(
versions,
(version) => version.compactVersion
);
return values(groupedVersions).map((groupedVersion) => groupedVersion[0]);
}
@alias('project.urlVersion')
urlVersion;
@computed('projectVersions.[]', 'model.version')
get selectedProjectVersion() {
return this.projectVersions.filter((pV) => pV.id === this.model.version)[0];
}
@readOnly('model.project.id')
activeProject;
@action
togglePrivateClasses() {
set(this, 'showPrivateClasses', !this.showPrivateClasses);
}
}