-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathfunction.js
72 lines (60 loc) · 1.67 KB
/
function.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
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import getFullVersion from 'ember-api-docs/utils/get-full-version';
import { set } from '@ember/object';
import createExcerpt from 'ember-api-docs/utils/create-excerpt';
export default class FunctionRoute extends Route {
@service
headData;
@service
metaStore;
@service
scrollPositionReset;
titleToken(model) {
return model?.fn?.name;
}
async model(params) {
const pVParams = this.paramsFor('project-version');
const { project, project_version: compactVersion } = pVParams;
let projectObj = await this.store.findRecord('project', project);
let projectVersion = getFullVersion(
compactVersion,
project,
projectObj,
this.metaStore
);
let className = params['module'];
let functionName = params['fn'];
let fnModule;
try {
fnModule = await this.store.find(
'class',
`${project}-${projectVersion}-${className}`
);
} catch (e) {
fnModule = await this.store.find(
'namespace',
`${project}-${projectVersion}-${className}`
);
}
return {
fnModule,
fn: fnModule.get('methods').find((fn) => fn.name === functionName),
};
}
afterModel(model) {
let description = model.fn.description;
if (description) {
set(this, 'headData.description', createExcerpt(description));
}
this.headData.functionName = model?.fn?.name;
}
getFunctionObjFromList(classObj, functionName) {
return classObj.get('methods').find((fn) => {
return fn.name === functionName;
});
}
activate() {
this.scrollPositionReset.doReset();
}
}