Moves tabs into Vue Component

This commit is contained in:
Filipa Lacerda 2017-03-14 09:30:57 +00:00
parent d51a5f0b4f
commit d3732b5529
3 changed files with 145 additions and 74 deletions

View file

@ -7,13 +7,10 @@ require('../vue_shared/vue_resource_interceptor');
require('./pipelines'); require('./pipelines');
$(() => new Vue({ $(() => new Vue({
el: document.querySelector('.vue-pipelines-index'), el: document.querySelector('#pipelines-list-vue'),
data() { data() {
const project = document.querySelector('.pipelines');
return { return {
scope: project.dataset.url,
store: new gl.PipelineStore(), store: new gl.PipelineStore(),
}; };
}, },
@ -21,9 +18,6 @@ $(() => new Vue({
'vue-pipelines': gl.VuePipelines, 'vue-pipelines': gl.VuePipelines,
}, },
template: ` template: `
<vue-pipelines <vue-pipelines :store="store"/>
:scope="scope"
:store="store">
</vue-pipelines>
`, `,
})); }));

View file

@ -18,10 +18,11 @@ const CommitPipelinesStoreWithTimeAgo = require('../commit/pipelines/pipelines_s
}, },
data() { data() {
const pipelinesData = document.querySelector('#pipelines-list-vue').dataset;
return { return {
...pipelinesData,
pipelines: [], pipelines: [],
timeLoopInterval: '',
intervalId: '',
apiScope: 'all', apiScope: 'all',
pageInfo: {}, pageInfo: {},
pagenum: 1, pagenum: 1,
@ -39,7 +40,7 @@ const CommitPipelinesStoreWithTimeAgo = require('../commit/pipelines/pipelines_s
if (pagenum) this.pagenum = pagenum; if (pagenum) this.pagenum = pagenum;
if (scope) this.apiScope = scope; if (scope) this.apiScope = scope;
this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.scope, this.apiScope); this.store.fetchDataLoop.call(this, Vue, this.pagenum, this.endpoint, this.apiScope);
}, },
beforeUpdate() { beforeUpdate() {
@ -49,12 +50,56 @@ const CommitPipelinesStoreWithTimeAgo = require('../commit/pipelines/pipelines_s
}, },
computed: { computed: {
canCreatePipelineParsed() {
return gl.utils.convertPermissionToBoolean(this.canCreatePipeline);
},
scope() {
return gl.utils.getParameterByName('scope');
},
shouldRenderErrorState() { shouldRenderErrorState() {
return this.hasError && !this.pageRequest; return this.hasError && !this.pageRequest;
}, },
/**
* The empty state should only be rendered when the request is made to fetch all pipelines
* and none is returned.
*
* @return {Boolean}
*/
shouldRenderEmptyState() { shouldRenderEmptyState() {
return !this.hasError && !this.pageRequest && !this.pipelines.length; return !this.hasError &&
!this.pageRequest && (
!this.pipelines.length && (this.scope === 'all' || this.scope === null)
);
},
shouldRenderTable() {
return !this.hasError &&
!this.pageRequest && this.pipelines.length;
},
/**
* Header tabs should only be rendered when we receive an error or a successfull response with
* pipelines.
*
* @return {Boolean}
*/
shouldRenderTabs() {
return !this.pageRequest && !this.hasError && this.pipelines.length;
},
/**
* Pagination should only be rendered when there is more than one page.
*
* @return {Boolean}
*/
shouldRenderPagination() {
return !this.pageRequest &&
this.pipelines.length &&
this.pageInfo.total > this.pageInfo.perPage;
}, },
}, },
@ -72,14 +117,80 @@ const CommitPipelinesStoreWithTimeAgo = require('../commit/pipelines/pipelines_s
}, },
}, },
template: ` template: `
<div> <div :class="cssClass">
<div class="pipelines realtime-loading" v-if='pageRequest'> <div class="top-area" v-if="!shouldRenderEmptyState">
<i class="fa fa-spinner fa-spin"></i> <ul
class="nav-links">
<li :class="{ 'active': scope === null || scope === 'all'}">
<a :href="allPath">
All
</a>
<span class="badge js-totalbuilds-count">
</span>
</li>
<li
class="js-pipelines-tab-pending"
:class="{ 'active': scope === 'pending'}">
<a :href="pendingPath">
Pending
</a>
<span class="badge"></span>
</li>
<li
class="js-pipelines-tab-running"
:class="{ 'active': scope === 'running'}">
<a :href="runningPath">Running</a>
<span class="badge"></span>
</li>
<li
class="js-pipelines-tab-finished"
:class="{ 'active': scope === 'finished'}">
<a :href="finishedPath">Finished</a>
<span class="badge"></span>
</li>
<li
class="js-pipelines-tab-branches"
:class="{ 'active': scope === 'branches'}">
<a :href="branchesPath">Branches</a>
</li>
<li
class="js-pipelines-tab-tags"
:class="{ 'active': scope === 'tags'}">
<a :href="tagsPath">Tags</a>
</li>
</ul>
<div class="nav-controls">
<a
v-if="canCreatePipelineParsed"
:href="newPipelinePath"
class="btn btn-create">
Run Pipeline
</a>
<a
v-if="!hasCi"
:href="helpPagePath"
class="btn btn-info">
Get started with Pipelines
</a>
<a
:href="ciLintPath"
class="btn btn-default">
CI Lint
</a>
</div>
</div>
<div class="pipelines realtime-loading"
v-if="pageRequest">
<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
</div> </div>
<div v-if="shouldRenderEmptyState" <div v-if="shouldRenderEmptyState"
class="row empty-state"> class="row empty-state">
<div class="col-xs-12 pull-right"> <div class="col-xs-12 pull-right">
<div class="svg-content"> <div class="svg-content">
${pipelinesEmptyStateSVG} ${pipelinesEmptyStateSVG}
@ -92,8 +203,7 @@ const CommitPipelinesStoreWithTimeAgo = require('../commit/pipelines/pipelines_s
<p> <p>
Continous Integration can help catch bugs by running your tests automatically, Continous Integration can help catch bugs by running your tests automatically,
while Continuous Deployment can help you deliver code to your product environment. while Continuous Deployment can help you deliver code to your product environment.
<a :href="helpPagePath" class="btn btn-info">
<a href="" class="btn btn-info">
Get started with Pipelines Get started with Pipelines
</a> </a>
</p> </p>
@ -103,7 +213,6 @@ const CommitPipelinesStoreWithTimeAgo = require('../commit/pipelines/pipelines_s
<div v-if="shouldRenderErrorState" <div v-if="shouldRenderErrorState"
class="row empty-state"> class="row empty-state">
<div class="col-xs-12 pull-right"> <div class="col-xs-12 pull-right">
<div class="svg-content"> <div class="svg-content">
${pipelinesErrorStateSVG} ${pipelinesErrorStateSVG}
@ -117,16 +226,17 @@ const CommitPipelinesStoreWithTimeAgo = require('../commit/pipelines/pipelines_s
</div> </div>
</div> </div>
<div class="table-holder" v-if='!pageRequest && pipelines.length'> <div class="table-holder"
v-if="shouldRenderTable">
<pipelines-table-component :pipelines='pipelines'/> <pipelines-table-component :pipelines='pipelines'/>
</div> </div>
<gl-pagination <gl-pagination
v-if='!pageRequest && pipelines.length && pageInfo.total > pageInfo.perPage' v-if="shouldRenderPagination"
:pagenum='pagenum' :pagenum="pagenum"
:change='change' :change="change"
:count='count.all' :count="count.all"
:pageInfo='pageInfo'/> :pageInfo="pageInfo"/>
</div> </div>
`, `,
}); });

View file

@ -2,53 +2,20 @@
- page_title "Pipelines" - page_title "Pipelines"
= render "projects/pipelines/head" = render "projects/pipelines/head"
%div{ class: container_class } - content_for :page_specific_javascripts do
.top-area = page_specific_javascript_bundle_tag("common_vue")
%ul.nav-links = page_specific_javascript_bundle_tag("vue_pipelines")
%li.js-pipelines-tab-all{ class: active_when(@scope.nil?) }>
= link_to project_pipelines_path(@project) do
All
%span.badge.js-totalbuilds-count
= number_with_delimiter(@pipelines_count)
%li.js-pipelines-tab-pending{ class: active_when(@scope == 'pending') }> #pipelines-list-vue{ data: { endpoint: namespace_project_pipelines_path(@project.namespace, @project, format: :json),
= link_to project_pipelines_path(@project, scope: :pending) do "css-class" => container_class,
Pending "help-page-path" => help_page_path('ci/quick_start/README'),
%span.badge "new-pipeline-path" => new_namespace_project_pipeline_path(@project.namespace, @project),
= number_with_delimiter(@pending_count) "can-create-pipeline" => can?(current_user, :create_pipeline, @project).to_s,
"all-path" => project_pipelines_path(@project),
%li.js-pipelines-tab-running{ class: active_when(@scope == 'running') }> "pending-path" => project_pipelines_path(@project, scope: :pending),
= link_to project_pipelines_path(@project, scope: :running) do "running-path" => project_pipelines_path(@project, scope: :running),
Running "finished-path" => project_pipelines_path(@project, scope: :finished),
%span.badge.js-running-count "branches-path" => project_pipelines_path(@project, scope: :branches),
= number_with_delimiter(@running_count) "tags-path" => project_pipelines_path(@project, scope: :tags),
"has-ci" => @repository.gitlab_ci_yml,
%li.js-pipelines-tab-finished{ class: active_when(@scope == 'finished') }> "ci-lint-path" => ci_lint_path } }
= link_to project_pipelines_path(@project, scope: :finished) do
Finished
%span.badge
= number_with_delimiter(@finished_count)
%li.js-pipelines-tab-branches{ class: active_when(@scope == 'branches') }>
= link_to project_pipelines_path(@project, scope: :branches) do
Branches
%li.js-pipelines-tab-tags{ class: active_when(@scope == 'tags') }>
= link_to project_pipelines_path(@project, scope: :tags) do
Tags
.nav-controls
- if can? current_user, :create_pipeline, @project
= link_to new_namespace_project_pipeline_path(@project.namespace, @project), class: 'btn btn-create' do
Run pipeline
- unless @repository.gitlab_ci_yml
= link_to 'Get started with Pipelines', help_page_path('ci/quick_start/README'), class: 'btn btn-info'
= link_to ci_lint_path, class: 'btn btn-default' do
%span CI Lint
.content-list.pipelines{ data: { url: namespace_project_pipelines_path(@project.namespace, @project, format: :json) } }
.vue-pipelines-index
= page_specific_javascript_bundle_tag('common_vue')
= page_specific_javascript_bundle_tag('vue_pipelines')