@@ -133,6 +133,69 @@ export default class ProjectVersionRoute extends Route {
133133 } ;
134134 }
135135
136+ @action
137+ updateProject ( project , ver /*, component */ ) {
138+ let projectVersionID = ver . compactVersion ;
139+ let endingRoute ;
140+ switch ( this . router . currentRouteName ) {
141+ case 'project-version.classes.class' : {
142+ let className = this . _getEncodedNameForCurrentClass ( ) ;
143+ endingRoute = `classes/${ className } ` ;
144+ break ;
145+ }
146+ case 'project-version.classes.class.index' : {
147+ let className = this . _getEncodedNameForCurrentClass ( ) ;
148+ endingRoute = `classes/${ className } ` ;
149+ break ;
150+ }
151+ case 'project-version.modules.module.index' : {
152+ let moduleName = encodeURIComponent (
153+ this . paramsFor ( 'project-version.modules.module' ) . module
154+ ) ;
155+ endingRoute = `modules/${ moduleName } ` ;
156+ break ;
157+ }
158+ case 'project-version.namespaces.namespace.index' : {
159+ let namespaceName = this . paramsFor (
160+ 'project-version.namespaces.namespace'
161+ ) . namespace ;
162+ endingRoute = `namespaces/${ namespaceName } ` ;
163+ break ;
164+ }
165+ default :
166+ endingRoute = '' ;
167+ break ;
168+ }
169+ // if the user is navigating to/from api versions >= 2.16, take them
170+ // to the home page instead of trying to translate the url
171+ let shouldConvertPackages = this . shouldConvertPackages (
172+ ver ,
173+ this . projectService . version
174+ ) ;
175+ let isEmberProject = project === 'ember' ;
176+ if ( ! isEmberProject || ! shouldConvertPackages ) {
177+ this . router . transitionTo (
178+ `/${ project } /${ projectVersionID } /${ endingRoute } `
179+ ) ;
180+ } else {
181+ this . router . transitionTo ( `/${ project } /${ projectVersionID } ` ) ;
182+ }
183+ }
184+
185+ // Input some version info, returns a boolean based on
186+ // whether the user is switching versions for a 2.16 docs release or later.
187+ // The urls for pre-2.16 classes and later packages are quite different
188+ shouldConvertPackages ( targetVer , previousVer ) {
189+ let targetVersion = getCompactVersion ( targetVer . id ) ;
190+ let previousVersion = getCompactVersion ( previousVer ) ;
191+ let previousComparison = semverCompare ( previousVersion , '2.16' ) ;
192+ let targetComparison = semverCompare ( targetVersion , '2.16' ) ;
193+ return (
194+ ( previousComparison < 0 && targetComparison >= 0 ) ||
195+ ( previousComparison >= 0 && targetComparison < 0 )
196+ ) ;
197+ }
198+
136199 /**
137200 splits the first encoded revision string in the list and takes the string after the version (which is the encoded name), then decodes the result.
138201 */
0 commit comments