Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c299f62a
Commit
c299f62a
authored
Dec 09, 2016
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wire up approvals front end and backend, mostly.
parent
3be2fb3f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
83 deletions
+68
-83
app/assets/javascripts/merge_request_widget/approvals/components/approvals_body.js.es6
...request_widget/approvals/components/approvals_body.js.es6
+5
-10
app/assets/javascripts/merge_request_widget/approvals/components/approvals_footer.js.es6
...quest_widget/approvals/components/approvals_footer.js.es6
+6
-10
app/assets/javascripts/merge_request_widget/approvals/services/approvals_api.js.es6
...ge_request_widget/approvals/services/approvals_api.js.es6
+18
-15
app/assets/javascripts/merge_request_widget/approvals/stores/approvals_store.js.es6
...ge_request_widget/approvals/stores/approvals_store.js.es6
+21
-8
app/assets/javascripts/merge_request_widget/widget_bundle.js.es6
...ets/javascripts/merge_request_widget/widget_bundle.js.es6
+6
-11
app/assets/javascripts/merge_request_widget/widget_store.js.es6
...sets/javascripts/merge_request_widget/widget_store.js.es6
+8
-26
app/views/projects/merge_requests/widget/_open.html.haml
app/views/projects/merge_requests/widget/_open.html.haml
+4
-3
No files found.
app/assets/javascripts/merge_request_widget/approvals/components/approvals_body.js.es6
View file @
c299f62a
...
...
@@ -2,13 +2,8 @@
//= require ../services/approvals_api
(() => {
const app = gl.MergeRequestWidget;
const api = app.ApprovalsApi;
const componentRegistry = app.Components || (app.Components = {});
componentRegistry.approvalsBody = {
name: 'ApprovalsBody',
Vue.component('approvals-body', {
name: 'approvals-body',
props: ['approverNames', 'approvalsLeft', 'userCanApprove', 'userHasApproved'],
data() {
return {
...
...
@@ -34,11 +29,11 @@
},
methods: {
approveMergeRequest() {
return
api.approveMergeRequest
();
return
gl.ApprovalsStore.approve
();
},
},
beforeCreate() {
api.fetchApprovals
().then(() => {
gl.ApprovalsStore.fetch
().then(() => {
this.loading = false;
});
},
...
...
@@ -57,5 +52,5 @@
<loading-icon v-if='loading'></loading-icon>
</div>
`,
};
}
)
;
})();
app/assets/javascripts/merge_request_widget/approvals/components/approvals_footer.js.es6
View file @
c299f62a
//= require ../s
ervices/approvals_api
//= require ../s
tores/approvals_store
//= require vue_common_component/link_to_member_avatar
//= require vue_common_component/loading_icon
(() => {
const app = gl.MergeRequestWidget;
const api = gl.MergeRequestWidget.ApprovalsApi;
const componentRegistry = app.Components || (app.Components = {});
componentRegistry.approvalsFooter =
{
name: '
ApprovalsF
ooter',
Vue.component('approvals-footer',
{
name: '
approvals-f
ooter',
props: ['userCanApprove', 'userHasApproved', 'approvedByUsers', 'approvalsLeft', 'pendingAvatarSvg', 'checkmarkSvg'],
data() {
return {
...
...
@@ -22,15 +19,14 @@
showUnapproveButton() {
return this.userCanApprove && this.userHasApproved;
},
},
methods: {
removeApproval() {
return
api.unapproveMergeRequest
();
return
gl.ApprovalsStore.unapprove
();
},
},
beforeCreate() {
api.fetchApprovals
().then(() => {
return gl.ApprovalsStore.fetch
().then(() => {
this.loading = false;
});
},
...
...
@@ -62,5 +58,5 @@
<loading-icon v-if='loading'></loading-icon>
</div>
`,
};
}
)
;
})();
app/assets/javascripts/merge_request_widget/approvals/services/approvals_api.js.es6
View file @
c299f62a
...
...
@@ -3,32 +3,35 @@
(() => {
class ApprovalsApi {
constructor() {
this.resource = gl.ApprovalsResource = new gl.SubbableResource('my/endpoint');
this.store = gl.MergeRequestWidget.ApprovalsStore;
constructor(endpoint) {
gl.ApprovalsApi = this;
this.init(endpoint);
}
init(mergeRequestEndpoint) {
const approvalsEndpoint = `${mergeRequestEndpoint}/approvals`;
this.resource = gl.ApprovalsResource = new gl.SubbableResource(approvalsEndpoint);
}
fetchApprovals() {
return this.resource.get();
return this.resource.get().fail((err) => {
console.error(`Error fetching approvals. ${err}`);
});
}
approveMergeRequest() {
return this.resource.post().
then((
) => {
gl.MergeRequestWidget.ApprovalsStore.approve(
);
return this.resource.post().
fail((err
) => {
console.error(`Error approving merge request. ${err}`
);
});
}
unapproveMergeRequest() {
return this.resource.delete().
then((
) => {
gl.MergeRequestWidget.ApprovalsStore.unapprove(
);
return this.resource.delete().
fail((err
) => {
console.error(`Error unapproving merge request. ${err}`
);
});
}
updateStore(newState = {}) {
this.store = gl.MergeRequestWidget.Store.data.approvals;
return Object.assign(this.store, newState);
}
}
gl.MergeRequestWidget.ApprovalsApi = new ApprovalsApi();
gl.ApprovalsApi = ApprovalsApi;
})();
app/assets/javascripts/merge_request_widget/approvals/stores/approvals_store.js.es6
View file @
c299f62a
//= require ../services/approvals_api
(() => {
let singleton;
class ApprovalsStore {
constructor(root
El
) {
constructor(root
Store
) {
if (!singleton) {
singleton = gl.
MergeRequestWidget.
ApprovalsStore = this;
this.init(root
El
);
singleton = gl.ApprovalsStore = this;
this.init(root
Store
);
}
return singleton;
}
init(rootEl) {
init(rootStore) {
this.rootStore = rootStore;
this.api = new gl.ApprovalsApi(rootStore.dataset.endpoint);
}
assignToRootStore(data) {
return this.rootStore.assignToData('approvals', data);
}
assignToData(val) {
fetch() {
return this.api.fetchApprovals({ type: 'GET' })
.then((data) => this.rootStore.assignToData(data));
}
/** TODO: remove after backend integerated */
approve() {
return this.api.approveMergeRequest({ type: 'POST' })
.then((data) => this.rootStore.assignToData(data));
}
unapprove() {
return this.api.unapproveMergeRequest({ type: 'DELETE' })
.then((data) => this.rootStore.assignToData(data));
}
}
gl.MergeRequestWidget.ApprovalsStore = ApprovalsStore;
gl.ApprovalsStore = ApprovalsStore;
})();
app/assets/javascripts/merge_request_widget/widget_bundle.js.es6
View file @
c299f62a
//= require ./widget_store
//= require ./approvals/services/approvals_api
//= require ./approvals/approvals_bundle
((MergeRequestWidget) => {
(() => {
$(() => {
const rootEl = document.getElementById('merge-request-widget-app');
const store = new MergeRequestWidget.Store(rootEl);
const components = MergeRequestWidget.Components;
const widgetSharedStore = new gl.MergeRequestWidgetStore(rootEl); // TODO: encapsulate better
MergeRequestWidget.
App = new Vue({
gl.MergeRequestWidget
App = new Vue({
el: rootEl,
data: store.data,
components: {
'approvals-body': components.approvalsBody,
'approvals-footer': components.approvalsFooter,
},
data: widgetSharedStore.data,
});
});
})(
gl.MergeRequestWidget || (gl.MergeRequestWidget
= {}));
})(
window.gl || (window.gl
= {}));
app/assets/javascripts/merge_request_widget/widget_store.js.es6
View file @
c299f62a
//= require ./approvals/stores/approvals_store
((
MergeRequestWidget
) => {
(() => {
let singleton;
class MergeRequestWidgetStore {
constructor(rootEl) {
if (!singleton) {
singleton = MergeRequestWidget.Store = this;
singleton =
gl.
MergeRequestWidget.Store = this;
this.init(rootEl);
}
return singleton;
// TODO: add the following to the root el dataset: approvedByUsers,
// approverNames, approvalsNeeded, canUpdateMergeRequest, endpoint
}
init(rootEl) {
this.rootEl = rootEl;
this.dataset = rootEl.dataset;
this.data = {};
this.initResource();
this.initPermissions();
this.initApprovals();
}
/* General Resources */
initResource() {
this.assignToData('resource', {
endpoint: 'my/endpoint',
});
}
initPermissions() {
this.assignToData('permissions', {
canUpdateMergeRequest: Boolean(this.dataset.canUpdateMergeRequest),
});
// init other widget stores here
this.initApprovals();
}
/* Component-specific */
initApprovals() {
const approvalsStore = new gl.
MergeRequestWidget.ApprovalsStore(this.rootEl
);
const approvalsStore = new gl.
ApprovalsStore(this
);
this.assignToData('approvals', approvalsStore.data);
}
...
...
@@ -48,6 +31,5 @@
Object.assign(this.data[key], val);
}
}
MergeRequestWidget.Store = MergeRequestWidgetStore;
})(gl.MergeRequestWidget || (MergeRequestWidget = {}));
gl.MergeRequestWidgetStore = MergeRequestWidgetStore;
})(window.gl || (window.gl = {}));
app/views/projects/merge_requests/widget/_open.html.haml
View file @
c299f62a
#merge-request-widget-app
.mr-state-widget
{
'data-endpoint'
=>
'/myendpoint/tho'
}
-
content_for
:page_specific_javascripts
do
=
page_specific_javascript_tag
(
'merge_request_widget/widget_bundle.js'
)
#merge-request-widget-app
.mr-state-widget
{
'data-approvals'
=>
@merge_request
.
approvals
.
to_json
,
'data-endpoint'
=>
merge_request_path
(
@merge_request
)}
=
render
'projects/merge_requests/widget/heading'
.mr-widget-body
-# After conflicts are resolved, the user is redirected back to the MR page.
...
...
@@ -50,6 +53,4 @@
-
if
@merge_request
.
approvals
.
any?
%approvals-footer
{
'pending-avatar-svg'
=>
custom_icon
(
'icon_dotted_circle'
),
'checkmark-svg'
=>
custom_icon
(
'icon_checkmark'
)
}
-
content_for
:page_specific_javascripts
do
=
page_specific_javascript_tag
(
'merge_request_widget/widget_bundle.js'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment