aboutsummaryrefslogtreecommitdiff
path: root/javascript/app/routes/package.js
blob: 6abc60332e4d9fbbf8e24c5cc3b6612aa78f6311 (plain) (blame)
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
import Ember from 'ember';
import {urls} from '../utils/api-urls';

export default Ember.Route.extend({
  store : Ember.inject.service('store'),
  model (params) {
    return this.get('store').loadPackage(params.packageId)
      .catch((e) => {console.log(e);this.transitionTo("/package-not-found");});
  },
  setupController(controller, model) {
    this._super(controller, model);
    controller.set('bottomPanelVisible',false);
  },
  actions : {
    openFile  (filePath) {
      this.transitionTo('package.show.file',filePath);
    },
    fileOpened (filePath) {
      if(this.get('controller')) {
        this.set('controller.currentFile',filePath);
      }
    },
    updateReferences(packageId,externalId,occName,locationInfo,noScrollIntoView) {
      this.get('store').loadGlobalReferences(externalId).then((refs) => {
        Ember.run.next(this,() => {
          this.set('controller.globalReferences',refs);
          if(!noScrollIntoView) {
            Ember.run.schedule('afterRender', () => {
              const element = document.getElementById('references-package-'+packageId);
              if(element) {
                element.scrollIntoView();
              }
            });
          }
        });
      });
      this.set('controller.packageId',packageId);
      this.set('controller.externalId',externalId);
      this.set('controller.occName',occName);
      this.set('controller.locationInfo',locationInfo);
      this.set('controller.bottomPanelVisible',true);
      this.set('controller.referencesUrl',urls.referencesUrl(packageId,externalId)+"?per_page=50");
    },
    didTransition() {
      document.title = this.currentModel.id;
      return true;
    }
  }
});