-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathapplication.js
86 lines (72 loc) · 2.43 KB
/
application.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
import { inject as service } from '@ember/service';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import { pluralize } from 'ember-inflector';
import { isBlank } from '@ember/utils';
export default class Application extends JSONAPIAdapter {
currentProject = '';
currentProjectVersion = '';
@service
metaStore;
@service('project')
projectService;
ids = null;
shouldReloadRecord(store, { modelName, id }) {
if (modelName === 'project') {
this.currentProject = id;
} else if (modelName === 'project-version') {
this.currentProjectVersion = id;
}
return; // return undefined so auto determinated
}
shouldBackgroundReloadAll() {
return false;
}
shouldBackgroundReloadRecord() {
return false;
}
constructor() {
super(...arguments);
this.ids = {};
}
async findRecord(store, { modelName }, id) {
let url;
// let host = this.host;
let projectName = this.currentProject;
if (['namespace', 'class', 'module'].indexOf(modelName) > -1) {
let [version] = id.replace(`${projectName}-`, '').split('-');
let revId = this.metaStore.getRevId(projectName, version, modelName, id);
let modelNameToUse = modelName;
// To account for namespaces that are also classes but not defined properly in yuidocs
if (isBlank(revId) && modelNameToUse === 'class') {
revId = this.metaStore.getRevId(projectName, version, 'namespace', id);
modelNameToUse = 'namespace';
}
if (typeof revId !== 'undefined') {
let encodedRevId = encodeURIComponent(revId);
url = `json-docs/${projectName}/${version}/${pluralize(
modelNameToUse
)}/${encodedRevId}`;
} else {
throw new Error('Documentation item not found');
}
} else if (modelName === 'missing') {
let version = this.projectService.version;
let revId = this.metaStore.getRevId(projectName, version, modelName, id);
url = `json-docs/${projectName}/${version}/${pluralize(
modelName
)}/${revId}`;
} else if (modelName === 'project') {
this.currentProject = id;
url = `rev-index/${id}`;
} else if (modelName === 'project-version') {
this.currentProjectVersion = id;
url = `rev-index/${id}`;
} else {
throw new Error('Unexpected model lookup');
}
url = `/${url}.json`;
let response = await fetch(url);
let json = await response.json();
return json;
}
}