diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2017-09-22 08:39:47 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-09-22 08:39:47 +0000 |
commit | 55f772bb98a67ad346442a2cacb5646f6719b987 (patch) | |
tree | fdcda42d5ee9c746b5654a50fa88a0fd1464d3a8 /app/assets/javascripts | |
parent | d103e95513704314a38ab8ae441851524031c4a1 (diff) | |
download | gitlab-ce-55f772bb98a67ad346442a2cacb5646f6719b987.tar.gz |
Resolve "Better SVG Usage in the Frontend"
Diffstat (limited to 'app/assets/javascripts')
16 files changed, 91 insertions, 70 deletions
diff --git a/app/assets/javascripts/boards/components/modal/empty_state.js b/app/assets/javascripts/boards/components/modal/empty_state.js index 13569df0c20..e571b11a83d 100644 --- a/app/assets/javascripts/boards/components/modal/empty_state.js +++ b/app/assets/javascripts/boards/components/modal/empty_state.js @@ -8,11 +8,11 @@ gl.issueBoards.ModalEmptyState = Vue.extend({ return ModalStore.store; }, props: { - image: { + newIssuePath: { type: String, required: true, }, - newIssuePath: { + emptyStateSvg: { type: String, required: true, }, @@ -42,7 +42,7 @@ gl.issueBoards.ModalEmptyState = Vue.extend({ <section class="empty-state"> <div class="row"> <div class="col-xs-12 col-sm-6 col-sm-push-6"> - <aside class="svg-content" v-html="image"></aside> + <aside class="svg-content"><img :src="emptyStateSvg"/></aside> </div> <div class="col-xs-12 col-sm-6 col-sm-pull-6"> <div class="text-content"> diff --git a/app/assets/javascripts/boards/components/modal/index.js b/app/assets/javascripts/boards/components/modal/index.js index 96af69e7a36..d2044f20ebe 100644 --- a/app/assets/javascripts/boards/components/modal/index.js +++ b/app/assets/javascripts/boards/components/modal/index.js @@ -12,11 +12,11 @@ const ModalStore = gl.issueBoards.ModalStore; gl.issueBoards.IssuesModal = Vue.extend({ props: { - blankStateImage: { + newIssuePath: { type: String, required: true, }, - newIssuePath: { + emptyStateSvg: { type: String, required: true, }, @@ -150,14 +150,14 @@ gl.issueBoards.IssuesModal = Vue.extend({ :label-path="labelPath"> </modal-header> <modal-list - :image="blankStateImage" :issue-link-base="issueLinkBase" :root-path="rootPath" + :empty-state-svg="emptyStateSvg" v-if="!loading && showList && !filterLoading"></modal-list> <empty-state v-if="showEmptyState" - :image="blankStateImage" - :new-issue-path="newIssuePath"></empty-state> + :new-issue-path="newIssuePath" + :empty-state-svg="emptyStateSvg"></empty-state> <section class="add-issues-list text-center" v-if="loading || filterLoading"> diff --git a/app/assets/javascripts/boards/components/modal/list.js b/app/assets/javascripts/boards/components/modal/list.js index b4a45feee4d..7c62134b3a3 100644 --- a/app/assets/javascripts/boards/components/modal/list.js +++ b/app/assets/javascripts/boards/components/modal/list.js @@ -15,7 +15,7 @@ gl.issueBoards.ModalList = Vue.extend({ type: String, required: true, }, - image: { + emptyStateSvg: { type: String, required: true, }, @@ -119,8 +119,8 @@ gl.issueBoards.ModalList = Vue.extend({ class="empty-state add-issues-empty-state-filter text-center" v-if="issuesCount > 0 && issues.length === 0"> <div - class="svg-content" - v-html="image"> + class="svg-content"> + <img :src="emptyStateSvg"/> </div> <div class="text-content"> <h4> diff --git a/app/assets/javascripts/commit/pipelines/pipelines_bundle.js b/app/assets/javascripts/commit/pipelines/pipelines_bundle.js index 16c5d0fa344..1f9153d95bd 100644 --- a/app/assets/javascripts/commit/pipelines/pipelines_bundle.js +++ b/app/assets/javascripts/commit/pipelines/pipelines_bundle.js @@ -35,6 +35,8 @@ document.addEventListener('DOMContentLoaded', () => { propsData: { endpoint: pipelineTableViewEl.dataset.endpoint, helpPagePath: pipelineTableViewEl.dataset.helpPagePath, + emptyStateSvgPath: pipelineTableViewEl.dataset.emptyStateSvgPath, + errorStateSvgPath: pipelineTableViewEl.dataset.errorStateSvgPath, autoDevopsHelpPath: pipelineTableViewEl.dataset.helpAutoDevopsPath, }, }).$mount(); diff --git a/app/assets/javascripts/commit/pipelines/pipelines_table.vue b/app/assets/javascripts/commit/pipelines/pipelines_table.vue index c931e1e0ea5..0661087a1ba 100644 --- a/app/assets/javascripts/commit/pipelines/pipelines_table.vue +++ b/app/assets/javascripts/commit/pipelines/pipelines_table.vue @@ -17,6 +17,14 @@ type: String, required: true, }, + emptyStateSvgPath: { + type: String, + required: true, + }, + errorStateSvgPath: { + type: String, + required: true, + }, }, mixins: [ pipelinesMixin, @@ -87,10 +95,12 @@ <empty-state v-if="shouldRenderEmptyState" :help-page-path="helpPagePath" + :empty-state-svg-path="emptyStateSvgPath" /> <error-state v-if="shouldRenderErrorState" + :error-state-svg-path="errorStateSvgPath" /> <div diff --git a/app/assets/javascripts/help/help.js b/app/assets/javascripts/help/help.js new file mode 100644 index 00000000000..4a22ebf187d --- /dev/null +++ b/app/assets/javascripts/help/help.js @@ -0,0 +1,6 @@ +// We will render the icons list here +if ($('#user-content-gitlab-icons').length > 0) { + const $iconsHeader = $('#user-content-gitlab-icons'); + const $iconsList = $('<div id="iconsList">ICONS</div>'); + $($iconsList).insertAfter($iconsHeader.parent()); +} diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index ead1b8f99d3..ea2d61af9be 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -408,6 +408,10 @@ export const setCiStatusFavicon = (pageUrl) => { }); }; +export const spriteIcon = icon => `<svg><use xlink:href="${gon.sprite_icons}#${icon}" /></svg>`; + +export const imagePath = imgUrl => `${gon.asset_host || ''}${gon.relative_url_root || ''}/assets/${imgUrl}`; + window.gl = window.gl || {}; window.gl.utils = { ...(window.gl.utils || {}), @@ -434,4 +438,6 @@ window.gl.utils = { getSelectedFragment, insertText, nodeMatchesSelector, + spriteIcon, + imagePath, }; diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 58d877f73fe..ec001b9b31c 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -8,6 +8,7 @@ import _ from 'underscore'; import Cookies from 'js-cookie'; import Dropzone from 'dropzone'; import Sortable from 'vendor/Sortable'; +import svg4everybody from 'svg4everybody'; // libraries with import side-effects import 'mousetrap'; @@ -151,6 +152,8 @@ if (process.env.NODE_ENV !== 'production') require('./test_utils/'); Dropzone.autoDiscover = false; +svg4everybody(); + document.addEventListener('beforeunload', function () { // Unbind scroll events $(document).off('scroll'); diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index f71a59aaa84..8ae127776e8 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -248,6 +248,8 @@ import { propsData: { endpoint: pipelineTableViewEl.dataset.endpoint, helpPagePath: pipelineTableViewEl.dataset.helpPagePath, + emptyStateSvgPath: pipelineTableViewEl.dataset.emptyStateSvgPath, + errorStateSvgPath: pipelineTableViewEl.dataset.errorStateSvgPath, autoDevopsHelpPath: pipelineTableViewEl.dataset.helpAutoDevopsPath, }, }).$mount(); diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue index 192473b7dd1..f80a26b3fd4 100644 --- a/app/assets/javascripts/monitoring/components/dashboard.vue +++ b/app/assets/javascripts/monitoring/components/dashboard.vue @@ -23,6 +23,9 @@ settingsPath: metricsData.settingsPath, metricsEndpoint: metricsData.additionalMetrics, deploymentEndpoint: metricsData.deploymentEndpoint, + emptyGettingStartedSvgPath: metricsData.emptyGettingStartedSvgPath, + emptyLoadingSvgPath: metricsData.emptyLoadingSvgPath, + emptyUnableToConnectSvgPath: metricsData.emptyUnableToConnectSvgPath, showEmptyState: true, updateAspectRatio: false, updatedAspectRatios: 0, @@ -109,5 +112,8 @@ :selected-state="state" :documentation-path="documentationPath" :settings-path="settingsPath" + :empty-getting-started-svg-path="emptyGettingStartedSvgPath" + :empty-loading-svg-path="emptyLoadingSvgPath" + :empty-unable-to-connect-svg-path="emptyUnableToConnectSvgPath" /> </template> diff --git a/app/assets/javascripts/monitoring/components/empty_state.vue b/app/assets/javascripts/monitoring/components/empty_state.vue index a8708be76de..a7b483f6786 100644 --- a/app/assets/javascripts/monitoring/components/empty_state.vue +++ b/app/assets/javascripts/monitoring/components/empty_state.vue @@ -1,8 +1,4 @@ <script> - import gettingStartedSvg from 'empty_states/monitoring/_getting_started.svg'; - import loadingSvg from 'empty_states/monitoring/_loading.svg'; - import unableToConnectSvg from 'empty_states/monitoring/_unable_to_connect.svg'; - export default { props: { documentationPath: { @@ -18,24 +14,36 @@ type: String, required: true, }, + emptyGettingStartedSvgPath: { + type: String, + required: true, + }, + emptyLoadingSvgPath: { + type: String, + required: true, + }, + emptyUnableToConnectSvgPath: { + type: String, + required: true, + }, }, data() { return { states: { gettingStarted: { - svg: gettingStartedSvg, + svgUrl: this.emptyGettingStartedSvgPath, title: 'Get started with performance monitoring', description: 'Stay updated about the performance and health of your environment by configuring Prometheus to monitor your deployments.', buttonText: 'Configure Prometheus', }, loading: { - svg: loadingSvg, + svgUrl: this.emptyLoadingSvgPath, title: 'Waiting for performance data', description: 'Creating graphs uses the data from the Prometheus server. If this takes a long time, ensure that data is available.', buttonText: 'View documentation', }, unableToConnect: { - svg: unableToConnectSvg, + svgUrl: this.emptyUnableToConnectSvgPath, title: 'Unable to connect to Prometheus server', description: 'Ensure connectivity is available from the GitLab server to the ', buttonText: 'View documentation', @@ -66,7 +74,9 @@ <template> <div class="prometheus-state"> <div class="row"> - <div class="col-md-4 col-md-offset-4 state-svg" v-html="currentState.svg"></div> + <div class="col-md-4 col-md-offset-4 state-svg svg-content"> + <img :src="currentState.svgUrl"/> + </div> </div> <div class="row"> <div class="col-md-6 col-md-offset-3"> diff --git a/app/assets/javascripts/notes/components/issue_note_icons.js b/app/assets/javascripts/notes/components/issue_note_icons.js deleted file mode 100644 index d8e3cb4bc01..00000000000 --- a/app/assets/javascripts/notes/components/issue_note_icons.js +++ /dev/null @@ -1,37 +0,0 @@ -import iconArrowCircle from 'icons/_icon_arrow_circle_o_right.svg'; -import iconCheck from 'icons/_icon_check_square_o.svg'; -import iconClock from 'icons/_icon_clock_o.svg'; -import iconCodeFork from 'icons/_icon_code_fork.svg'; -import iconComment from 'icons/_icon_comment_o.svg'; -import iconCommit from 'icons/_icon_commit.svg'; -import iconEdit from 'icons/_icon_edit.svg'; -import iconEye from 'icons/_icon_eye.svg'; -import iconEyeSlash from 'icons/_icon_eye_slash.svg'; -import iconMerge from 'icons/_icon_merge.svg'; -import iconMerged from 'icons/_icon_merged.svg'; -import iconRandom from 'icons/_icon_random.svg'; -import iconClosed from 'icons/_icon_status_closed.svg'; -import iconStatusOpen from 'icons/_icon_status_open.svg'; -import iconStopwatch from 'icons/_icon_stopwatch.svg'; -import iconTags from 'icons/_icon_tags.svg'; -import iconUser from 'icons/_icon_user.svg'; - -export default { - icon_arrow_circle_o_right: iconArrowCircle, - icon_check_square_o: iconCheck, - icon_clock_o: iconClock, - icon_code_fork: iconCodeFork, - icon_comment_o: iconComment, - icon_commit: iconCommit, - icon_edit: iconEdit, - icon_eye: iconEye, - icon_eye_slash: iconEyeSlash, - icon_merge: iconMerge, - icon_merged: iconMerged, - icon_random: iconRandom, - icon_status_closed: iconClosed, - icon_status_open: iconStatusOpen, - icon_stopwatch: iconStopwatch, - icon_tags: iconTags, - icon_user: iconUser, -}; diff --git a/app/assets/javascripts/notes/components/issue_system_note.vue b/app/assets/javascripts/notes/components/issue_system_note.vue index 5bb8f871b9d..0cfb6522e77 100644 --- a/app/assets/javascripts/notes/components/issue_system_note.vue +++ b/app/assets/javascripts/notes/components/issue_system_note.vue @@ -1,6 +1,5 @@ <script> import { mapGetters } from 'vuex'; - import iconsMap from './issue_note_icons'; import issueNoteHeader from './issue_note_header.vue'; export default { @@ -24,9 +23,9 @@ isTargetNote() { return this.targetNoteHash === this.noteAnchorId; }, - }, - created() { - this.svg = iconsMap[this.note.system_note_icon_name]; + iconHtml() { + return gl.utils.spriteIcon(this.note.system_note_icon_name); + }, }, }; </script> @@ -39,7 +38,7 @@ <div class="timeline-entry-inner"> <div class="timeline-icon" - v-html="svg"> + v-html="iconHtml"> </div> <div class="timeline-content"> <div class="note-header"> diff --git a/app/assets/javascripts/pipelines/components/empty_state.vue b/app/assets/javascripts/pipelines/components/empty_state.vue index 3db64339a62..0eaac8dd64f 100644 --- a/app/assets/javascripts/pipelines/components/empty_state.vue +++ b/app/assets/javascripts/pipelines/components/empty_state.vue @@ -1,21 +1,24 @@ <script> -import pipelinesEmptyStateSVG from 'empty_states/icons/_pipelines_empty.svg'; - export default { props: { helpPagePath: { type: String, required: true, }, + emptyStateSvgPath: { + type: String, + required: true, + }, }, - data: () => ({ pipelinesEmptyStateSVG }), }; </script> <template> <div class="row empty-state js-empty-state"> <div class="col-xs-12"> - <div class="svg-content" v-html="pipelinesEmptyStateSVG" /> + <div class="svg-content"> + <img :src="emptyStateSvgPath"/> + </div> </div> <div class="col-xs-12 text-center"> diff --git a/app/assets/javascripts/pipelines/components/error_state.vue b/app/assets/javascripts/pipelines/components/error_state.vue index 90cee68163e..012853b201d 100644 --- a/app/assets/javascripts/pipelines/components/error_state.vue +++ b/app/assets/javascripts/pipelines/components/error_state.vue @@ -1,15 +1,20 @@ <script> -import pipelinesErrorStateSVG from 'empty_states/icons/_pipelines_failed.svg'; - export default { - data: () => ({ pipelinesErrorStateSVG }), + props: { + errorStateSvgPath: { + type: String, + required: true, + }, + }, }; </script> <template> <div class="row empty-state js-pipelines-error-state"> <div class="col-xs-12"> - <div class="svg-content" v-html="pipelinesErrorStateSVG" /> + <div class="svg-content"> + <img :src="errorStateSvgPath"/> + </div> </div> <div class="col-xs-12 text-center"> diff --git a/app/assets/javascripts/pipelines/components/pipelines.vue b/app/assets/javascripts/pipelines/components/pipelines.vue index 4c53e2541fc..085bd20cefe 100644 --- a/app/assets/javascripts/pipelines/components/pipelines.vue +++ b/app/assets/javascripts/pipelines/components/pipelines.vue @@ -27,6 +27,8 @@ return { endpoint: pipelinesData.endpoint, helpPagePath: pipelinesData.helpPagePath, + emptyStateSvgPath: pipelinesData.emptyStateSvgPath, + errorStateSvgPath: pipelinesData.errorStateSvgPath, autoDevopsPath: pipelinesData.helpAutoDevopsPath, newPipelinePath: pipelinesData.newPipelinePath, canCreatePipeline: pipelinesData.canCreatePipeline, @@ -182,9 +184,13 @@ <empty-state v-if="shouldRenderEmptyState" :help-page-path="helpPagePath" + :empty-state-svg-path="emptyStateSvgPath" /> - <error-state v-if="shouldRenderErrorState" /> + <error-state + v-if="shouldRenderErrorState" + :error-state-svg-path="errorStateSvgPath" + /> <div class="blank-state blank-state-no-icon" |