repo_file_buttons.js 1.8 KB
Newer Older
1 2 3 4
import Vue from 'vue';
import Store from './repo_store';
import Helper from './repo_helper';
import RepoMiniMixin from './repo_mini_mixin';
Jacob Schatz's avatar
Jacob Schatz committed
5

6
export default class RepoFileButtons {
7 8
  constructor(el) {
    this.initVue(el);
Jacob Schatz's avatar
Jacob Schatz committed
9
  }
10

11
  initVue(el) {
Jacob Schatz's avatar
Jacob Schatz committed
12
    this.vue = new Vue({
13
      el,
Jacob Schatz's avatar
Jacob Schatz committed
14
      data: () => Store,
15
      mixins: [RepoMiniMixin],
Jacob Schatz's avatar
Jacob Schatz committed
16
      template: `
17
      <div id='repo-file-buttons' v-if='isMini' :style='{"border-bottom": editableBorder}'>
18
        <a :href='rawFileURL' target='_blank' class='btn btn-default'>Raw</a>
19

Jacob Schatz's avatar
Jacob Schatz committed
20 21 22 23 24 25
        <div class="btn-group" role="group" aria-label="File actions">
          <a :href='blameFileUrl' class='btn btn-default'>Blame</a>
          <a :href='historyFileUrl' class='btn btn-default'>History</a>
          <a href='#' class='btn btn-default'>Permalink</a>
          <a href='#' class='btn btn-default'>Lock</a>
        </div>
26

27 28 29
        <a href='#' v-if='canPreview' @click.prevent='rawPreviewToggle' class='btn btn-default'>
          {{activeFileLabel}}
        </a>
30 31 32

        <button type="button" class="btn btn-default" data-target="#modal-upload-blob" data-toggle="modal">Replace</button>

Jacob Schatz's avatar
Jacob Schatz committed
33 34 35 36
        <a href='#' class='btn btn-danger'>Delete</a>
      </div>
      `,
      computed: {
37 38

        editableBorder() {
39
          return this.editMode ? '1px solid #1F78D1' : '1px solid #f0f0f0';
Jacob Schatz's avatar
Jacob Schatz committed
40 41 42 43 44 45
        },

        canPreview() {
          return this.activeFile.extension === 'md';
        },

46
        rawFileURL() {
Jacob Schatz's avatar
Jacob Schatz committed
47 48 49 50 51 52 53 54 55
          return Helper.getRawURLFromBlobURL(this.activeFile.url);
        },

        blameFileUrl() {
          return Helper.getBlameURLFromBlobURL(this.activeFile.url);
        },

        historyFileUrl() {
          return Helper.getHistoryURLFromBlobURL(this.activeFile.url);
56
        },
Jacob Schatz's avatar
Jacob Schatz committed
57 58 59
      },

      methods: {
60
        rawPreviewToggle: Store.toggleRawPreview,
61
      },
Jacob Schatz's avatar
Jacob Schatz committed
62 63
    });
  }
64
}