| 7 | import createExcerpt from 'ember-api-docs/utils/create-excerpt'; |
| 8 | |
| 9 | export default class ClassRoute extends Route { |
| 10 | /** @type {import('@ember/routing/router-service').default} */ |
| 11 | @service |
| 12 | router; |
| 13 | |
| 14 | @service |
| 15 | headData; |
| 16 | |
| 17 | @service |
| 18 | metaStore; |
| 19 | |
| 20 | @service store; |
| 21 | |
| 22 | async model(params) { |
| 23 | const { project, project_version: compactVersion } = |
| 24 | this.paramsFor('project-version'); |
| 25 | let projectObj = await this.store.findRecord('project', project); |
| 26 | let projectVersion = getFullVersion( |
| 27 | compactVersion, |
| 28 | project, |
| 29 | projectObj, |
| 30 | this.metaStore, |
| 31 | ); |
| 32 | const klass = params['class']; |
| 33 | return this.find( |
| 34 | 'class', |
| 35 | `${project}-${projectVersion}-${klass}`.toLowerCase(), |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | find(typeName, param) { |
| 40 | return this.store.findRecord(typeName, param).catch((e1) => { |
| 41 | if (typeName != 'namespace') { |
| 42 | console.warn( |
| 43 | e1, |
| 44 | 'fetching by class or module failed, retrying as namespace', |
| 45 | ); |
| 46 | return this.store.findRecord('namespace', param).catch((e2) => { |
| 47 | console.error(e2); |
| 48 | return resolve({ |
| 49 | isError: true, |
| 50 | status: 404, |
| 51 | }); |
| 52 | }); |
| 53 | } |
| 54 | console.error(e1); |
| 55 | return resolve({ |
| 56 | isError: true, |
| 57 | status: 404, |
| 58 | }); |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | redirect(model, transition) { |
| 63 | if (model.isError) { |
| 64 | // Transitioning to the same route, probably only changing version |
| 65 | // Could explicitly check by comparing transition.to and transition.from |
| 66 | if (transition.to.name === transition?.from?.name) { |
nothing calls this directly
no outgoing calls
no test coverage detected