diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-22 18:07:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-22 18:07:25 +0300 |
commit | e01b61d83fd7c5d3aa9d87a65eac85e8c7ea9921 (patch) | |
tree | 90e1a1f3ebbeab0f2f8714f42211800a213a1002 /app/assets/javascripts/blob | |
parent | 4220cf46a314ac1c4d88be13608752bc07bb28fb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r-- | app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js | 111 | ||||
-rw-r--r-- | app/assets/javascripts/blob/balsamiq_viewer.js | 22 | ||||
-rw-r--r-- | app/assets/javascripts/blob/viewer/index.js | 2 |
3 files changed, 0 insertions, 135 deletions
diff --git a/app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js b/app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js deleted file mode 100644 index 313bec7e01a..00000000000 --- a/app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js +++ /dev/null @@ -1,111 +0,0 @@ -import { template as _template } from 'lodash'; -import sqljs from 'sql.js'; -import axios from '~/lib/utils/axios_utils'; -import { successCodes } from '~/lib/utils/http_status'; - -const PREVIEW_TEMPLATE = _template(` - <div class="card"> - <div class="card-header"><%- name %></div> - <div class="card-body"> - <img class="img-thumbnail" src="data:image/png;base64,<%- image %>"/> - </div> - </div> -`); - -class BalsamiqViewer { - constructor(viewer) { - this.viewer = viewer; - } - - loadFile(endpoint) { - return axios - .get(endpoint, { - responseType: 'arraybuffer', - validateStatus(status) { - return status !== successCodes.OK; - }, - }) - .then(({ data }) => { - this.renderFile(data); - }) - .catch((e) => { - throw new Error(e); - }); - } - - renderFile(fileBuffer) { - const container = document.createElement('ul'); - - this.initDatabase(fileBuffer); - - const previews = this.getPreviews(); - previews.forEach((preview) => { - const renderedPreview = this.renderPreview(preview); - - container.appendChild(renderedPreview); - }); - - container.classList.add('list-inline'); - container.classList.add('previews'); - - this.viewer.appendChild(container); - } - - initDatabase(data) { - const previewBinary = new Uint8Array(data); - - this.database = new sqljs.Database(previewBinary); - } - - getPreviews() { - const thumbnails = this.database.exec('SELECT * FROM thumbnails'); - - return thumbnails[0].values.map(BalsamiqViewer.parsePreview); - } - - getResource(resourceID) { - const resources = this.database.exec(`SELECT * FROM resources WHERE id = '${resourceID}'`); - - return resources[0]; - } - - renderPreview(preview) { - const previewElement = document.createElement('li'); - - previewElement.classList.add('preview'); - previewElement.innerHTML = this.renderTemplate(preview); - - return previewElement; - } - - renderTemplate(preview) { - const resource = this.getResource(preview.resourceID); - const name = BalsamiqViewer.parseTitle(resource); - const { image } = preview; - - const template = PREVIEW_TEMPLATE({ - name, - image, - }); - - return template; - } - - static parsePreview(preview) { - return JSON.parse(preview[1]); - } - - /* - * resource = { - * columns: ['ID', 'BRANCHID', 'ATTRIBUTES', 'DATA'], - * values: [['id', 'branchId', 'attributes', 'data']], - * } - * - * 'attributes' being a JSON string containing the `name` property. - */ - static parseTitle(resource) { - return JSON.parse(resource.values[0][2]).name; - } -} - -export default BalsamiqViewer; diff --git a/app/assets/javascripts/blob/balsamiq_viewer.js b/app/assets/javascripts/blob/balsamiq_viewer.js deleted file mode 100644 index af8e8a4cd3d..00000000000 --- a/app/assets/javascripts/blob/balsamiq_viewer.js +++ /dev/null @@ -1,22 +0,0 @@ -import createFlash from '~/flash'; -import { __ } from '~/locale'; -import BalsamiqViewer from './balsamiq/balsamiq_viewer'; - -function onError() { - const flash = createFlash({ - message: __('Balsamiq file could not be loaded.'), - }); - - return flash; -} - -export default function loadBalsamiqFile() { - const viewer = document.getElementById('js-balsamiq-viewer'); - - if (!(viewer instanceof Element)) return; - - const { endpoint } = viewer.dataset; - - const balsamiqViewer = new BalsamiqViewer(viewer); - balsamiqViewer.loadFile(endpoint).catch(onError); -} diff --git a/app/assets/javascripts/blob/viewer/index.js b/app/assets/javascripts/blob/viewer/index.js index 1bda7d4e3f0..49b6f042911 100644 --- a/app/assets/javascripts/blob/viewer/index.js +++ b/app/assets/javascripts/blob/viewer/index.js @@ -17,8 +17,6 @@ import eventHub from '../../notes/event_hub'; const loadRichBlobViewer = (type) => { switch (type) { - case 'balsamiq': - return import(/* webpackChunkName: 'balsamiq_viewer' */ '../balsamiq_viewer'); case 'notebook': return import(/* webpackChunkName: 'notebook_viewer' */ '../notebook_viewer'); case 'openapi': |