diff_viewer.vue 1.67 KB
Newer Older
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
<script>
import { viewerInformationForPath } from '../content_viewer/lib/viewer_utils';
import ImageDiffViewer from './viewers/image_diff_viewer.vue';
import DownloadDiffViewer from './viewers/download_diff_viewer.vue';

export default {
  props: {
    diffMode: {
      type: String,
      required: true,
    },
    newPath: {
      type: String,
      required: true,
    },
    newSha: {
      type: String,
      required: true,
    },
    oldPath: {
      type: String,
      required: true,
    },
    oldSha: {
      type: String,
      required: true,
    },
    projectPath: {
      type: String,
      required: false,
      default: '',
    },
  },
  computed: {
    viewer() {
      if (!this.newPath) return null;

      const previewInfo = viewerInformationForPath(this.newPath);
      if (!previewInfo) return DownloadDiffViewer;

      switch (previewInfo.id) {
        case 'image':
          return ImageDiffViewer;
        default:
          return DownloadDiffViewer;
      }
    },
48
    basePath() {
49
      // We might get the project path from rails with the relative url already set up
50
51
      return this.projectPath.indexOf('/') === 0 ? '' : `${gon.relative_url_root}/`;
    },
52
    fullOldPath() {
53
      return `${this.basePath}${this.projectPath}/raw/${this.oldSha}/${this.oldPath}`;
54
55
    },
    fullNewPath() {
56
      return `${this.basePath}${this.projectPath}/raw/${this.newSha}/${this.newPath}`;
57
58
59
60
61
62
63
    },
  },
};
</script>

<template>
  <div
Filipa Lacerda's avatar
Filipa Lacerda committed
64
65
    v-if="viewer"
    class="diff-file preview-container">
66
67
68
69
70
71
72
73
74
    <component
      :is="viewer"
      :diff-mode="diffMode"
      :new-path="fullNewPath"
      :old-path="fullOldPath"
      :project-path="projectPath"
    />
  </div>
</template>