Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ide_router.js « ide « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4231acc3b3d16f57e823c5536c5572d9965daee1 (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import Vue from 'vue';
import VueRouter from 'vue-router';
import store from './stores';

Vue.use(VueRouter);

/**
 * Routes below /-/ide/:

/project/h5bp/html5-boilerplate/blob/master
/project/h5bp/html5-boilerplate/blob/master/app/js/test.js

/project/h5bp/html5-boilerplate/mr/123
/project/h5bp/html5-boilerplate/mr/123/app/js/test.js

/workspace/123
/workspace/project/h5bp/html5-boilerplate/blob/my-special-branch
/workspace/project/h5bp/html5-boilerplate/mr/123

/ = /workspace
/settings

 */

// Unfortunately Vue Router doesn't work without at least a fake component
// If you do only data handling
const FooRouterComponent = {
  template: '<div>foo</div>',
};

const router = new VueRouter({
  mode: 'history',
  base: '/-/ide/',
  routes: [
    {
      path: '/project/:namespace/:project',
      component: FooRouterComponent,
      children: [
        {
          path: ':targetmode/:branch/*',
          component: FooRouterComponent,
        },
        {
          path: 'mr/:mrid',
          component: FooRouterComponent,
        },
      ],
    },
  ],
});

router.beforeEach((to, from, next) => {
  console.log('BEFORE EACH : ',to);

  store.dispatch('getProjectData', {
    namespace: to.params.namespace,
    projectId: to.params.project,
  })
  .then(() => {
    if (to.params.branch) {
      store.dispatch('getBranchData', {
        namespace: to.params.namespace,
        projectId: to.params.project,
        branch: to.params.branch,
      });

      store.dispatch('getTreeData', {
        namespace: to.params.namespace,
        projectId: to.params.project,
        branch: to.params.branch,
        endpoint: `/${to.params.namespace}/${to.params.project}/tree/${to.params.branch}`,
      })
      .then(() => {
        if (to.params[0]) {
        const treeEntry = store.getters.getTreeEntry(`${to.params.namespace}/${to.params.project}/${to.params.branch}`, to.params[0]);
          if (treeEntry) {
            console.log('To Selected File : ', to.params, '/', treeEntry.url);
            store.dispatch('handleTreeEntryAction', treeEntry);
          }
        } else {
          throw (new Error(`Tree entry for ${to.params[0]} doesn't exist`));
        }
      })
      .catch((e) => {
        debugger;
        //next(false);
      });

      if (!to.params[0]) {
        // We are in the root of the tree
        console.log('Load Branch Tree');
      } else {
        
      }
    }
  })
  .catch((e) => {
    debugger;
    //next(false);
  });
  next();
});

export default router;