Skip to content

Use next gen api docs #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ module.exports = {
ecmaVersion: 2017,
sourceType: 'module'
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
env: {
browser: true
},
Expand All @@ -33,6 +28,7 @@ module.exports = {
'lib/**/*.js',
'bin/*',
'server/**/*.js',
'.prettierrc.js'
],
excludedFiles: ['config/deprecation-workflow.js'],
parserOptions: {
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
singleQuote: true,
printWidth: 100
};
56 changes: 38 additions & 18 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
import { inject as service } from '@ember/service';
import DS from 'ember-data';
import fetch from 'fetch';
import { get } from '@ember/object';
import { isBlank } from '@ember/utils';
import ENV from 'ember-api-docs/config/environment';
import DS from 'ember-data';
import { pluralize } from 'ember-inflector';
import { isBlank } from '@ember/utils';
import fetch from 'fetch';

const { JSONAPIAdapter } = DS;

export default JSONAPIAdapter.extend({

host: ENV.API_HOST,

currentProject: '',

currentProjectVersion: '',

metaStore: service(),
projectService: service('project'),
shouldBackgroundReloadAll() {
return false;
},

shouldBackgroundReloadRecord() {
return false;
},

setCurrentProjectInfo(id) {
let [project, version] = id.split('-');
this.currentProjectVersion = version;
this.currentProject = project;
},

shouldBackgroundReloadAll() { return false; },
shouldBackgroundReloadRecord() { return false; },
getRevId(type, id) {
let encodedId = encodeURIComponent(id);
let projectVersionDoc = this.store.peekRecord(
'project-version',
`${this.currentProject}-${this.currentProjectVersion}`
);
return get(projectVersionDoc, 'revMap')[type][encodedId];
},

async findRecord(store, {modelName}, id) {
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);
if (isBlank(this.currentProjectVersion)) {
this.setCurrentProjectInfo(id);
}

let version = this.currentProjectVersion;
let revId = this.getRevId(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);
revId = this.getRevId('namespace', id);
modelNameToUse = 'namespace';
}

Expand All @@ -44,13 +64,14 @@ export default JSONAPIAdapter.extend({
throw new Error('Documentation item not found');
}
} else if (modelName === 'missing') {
let version = this.get('projectService.version');
let revId = this.metaStore.getRevId(projectName, version, modelName, id);
let version = this.currentProjectVersion;
let revId = this.getRevId(modelName, id);
url = `json-docs/${projectName}/${version}/${pluralize(modelName)}/${revId}`;
} else if (modelName === 'project') {
this.set('currentProject', id);
this.currentProject = id;
url = `rev-index/${id}`;
} else if (modelName === 'project-version') {
this.setCurrentProjectInfo(id);
url = `rev-index/${id}`;
} else {
throw new Error('Unexpected model lookup');
Expand All @@ -61,6 +82,5 @@ export default JSONAPIAdapter.extend({
let response = await fetch(url);
let json = await response.json();
return json;
}

},
});
52 changes: 27 additions & 25 deletions app/controllers/project-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ import { computed } from '@ember/object';
import { alias, readOnly } from '@ember/object/computed';
import { A } from '@ember/array';
import { inject as service } from '@ember/service';
import values from 'lodash.values';
import groupBy from 'lodash.groupby';
import semverCompare from 'semver-compare';
import getCompactVersion from '../utils/get-compact-version';

export default Controller.extend({

filterData: service(),

metaStore: service(),

project: service(),

showPrivateClasses: alias('filterData.sideNav.showPrivate'),
Expand Down Expand Up @@ -44,11 +38,14 @@ export default Controller.extend({

getModuleRelationships(versionId, moduleType) {
let relations = this.getRelations(moduleType);
return relations.map(id => id.substring(versionId.length + 1))
return relations.map(id => id.substring(versionId.length + 1));
},

getRelations(relationship) {
return this.model.hasMany(relationship).ids().sort();
return this.model
.hasMany(relationship)
.ids()
.sort();
},

getRelationshipIDs(relationship) {
Expand All @@ -57,7 +54,14 @@ export default Controller.extend({
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('-'));
return A(sorted)
.toArray()
.map(id =>
id
.split('-')
.slice(splitPoint)
.join('-')
);
},

shownClassesIDs: computed('showPrivateClasses', 'classesIDs', 'publicClassesIDs', function() {
Expand All @@ -68,26 +72,24 @@ export default Controller.extend({
return this.showPrivateClasses ? this.moduleIDs : this.publicModuleIDs;
}),

shownNamespaceIDs: computed('showPrivateClasses', 'namespaceIDs', 'publicNamespaceIDs', function() {
return this.showPrivateClasses ? this.namespaceIDs : this.publicNamespaceIDs;
}),

projectVersions: computed('metaStore.availableProjectVersions', 'model.project.id', function() {
const projectVersions = this.get('metaStore.availableProjectVersions')[this.get('model.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]);
shownNamespaceIDs: computed(
'showPrivateClasses',
'namespaceIDs',
'publicNamespaceIDs',
function() {
return this.showPrivateClasses ? this.namespaceIDs : this.publicNamespaceIDs;
}
),

projectVersions: computed('model.project.{id,availableVersions.[]}', function() {
return this.model
.get('project.availableVersions')
.map(version => ({ id: version, compactVersion: getCompactVersion(version) }));
}),

urlVersion: alias('project.urlVersion'),

selectedProjectVersion:computed('projectVersions.[]', 'model.version', function() {
selectedProjectVersion: computed('projectVersions.[]', 'model.version', function() {
return this.projectVersions.filter(pV => pV.id === this.get('model.version'))[0];
}),

Expand Down
14 changes: 6 additions & 8 deletions app/controllers/project-version/classes/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import FilterParams from 'ember-api-docs/mixins/filter-params';
export default Controller.extend(ParentNameMixin, FilterParams, {
filterData: service(),
legacyModuleMappings: service(),
metaStore: service(),

hasImportExample: computed('model.name', 'legacyModuleMappings.mappings', function () {
return this.legacyModuleMappings.hasClassMapping(this.get('model.name'), this.get('model.module'));
hasImportExample: computed('model.name', 'legacyModuleMappings.mappings', function() {
return this.legacyModuleMappings.hasClassMapping(
this.get('model.name'),
this.get('model.module')
);
}),

module: computed('model.name', 'legacyModulemappings.mappings', function () {
module: computed('model.name', 'legacyModulemappings.mappings', function() {
return this.legacyModuleMappings.getModule(this.get('model.name'), this.get('model.module'));
}),

allVersions: computed('model.project.id', function() {
return this.get('metaStore.availableProjectVersions')[this.get('model.project.id')];
}),

actions: {
updateFilter(filter) {
this.toggleProperty(`filterData.${filter}`);
Expand Down
9 changes: 0 additions & 9 deletions app/helpers/is-latest.js

This file was deleted.

21 changes: 0 additions & 21 deletions app/instance-initializers/ember-meta-store.js

This file was deleted.

33 changes: 22 additions & 11 deletions app/models/project-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ import getCompactVersion from '../utils/get-compact-version';

export default DS.Model.extend({
version: DS.attr(),
classes: DS.hasMany('class', {async: true}),
modules: DS.hasMany('module', {async: true}),
namespaces: DS.hasMany('namespace', {async: true}),
'public-classes': DS.hasMany('class', {async: true}),
'private-classes': DS.hasMany('class', {async: true}),
'public-modules': DS.hasMany('module', {async: true}),
'private-modules': DS.hasMany('module', {async: true}),
'public-namespaces': DS.hasMany('namespace', {async: true}),
'private-namespaces': DS.hasMany('namespace', {async: true}),
revMap: DS.attr(),
classes: DS.hasMany('class', { async: true }),
modules: DS.hasMany('module', { async: true }),
namespaces: DS.hasMany('namespace', { async: true }),
'public-classes': DS.hasMany('class', { async: true }),
'private-classes': DS.hasMany('class', { async: true }),
'public-modules': DS.hasMany('module', { async: true }),
'private-modules': DS.hasMany('module', { async: true }),
'public-namespaces': DS.hasMany('namespace', { async: true }),
'private-namespaces': DS.hasMany('namespace', { async: true }),
project: DS.belongsTo('project'),
compactVersion: computed('version', function() {
compactVersion: computed('version', function () {
return getCompactVersion(this.version);
})
}),

firstModule: computed('modules.[]', function () {
let moduleNames = Object.keys(this.revMap.module).sort();
let encodedModule = moduleNames[0]
.split('-')
.reduce((result, val, index, arry) =>
val === this.version ? arry.slice(index + 1).join('-') : result
);
return decodeURIComponent(encodedModule);
}),
});
5 changes: 3 additions & 2 deletions app/models/project.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import DS from 'ember-data';

const {Model, attr, hasMany} = DS;
const { Model, attr, hasMany } = DS;

export default Model.extend({
name: attr(),
githubUrl: attr(),
projectVersions: hasMany('project-version', {async: true})
availableVersions: attr(),
projectVersions: hasMany('project-version', { async: true })
});
Loading