Commit dc73405d authored by Phil Hughes's avatar Phil Hughes

Uses dataset rather than jQuery to get attribute values

parent 1de23708
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
//= require ./components/new_list_dropdown //= require ./components/new_list_dropdown
$(() => { $(() => {
const $boardApp = $('#board-app'); const $boardApp = document.getElementById('board-app'),
Store = gl.issueBoards.BoardsStore;
window.gl = window.gl || {}; window.gl = window.gl || {};
...@@ -18,16 +19,16 @@ $(() => { ...@@ -18,16 +19,16 @@ $(() => {
} }
gl.IssueBoardsApp = new Vue({ gl.IssueBoardsApp = new Vue({
el: $boardApp.get(0), el: $boardApp,
components: { components: {
'board': gl.issueBoards.Board 'board': gl.issueBoards.Board
}, },
data: { data: {
state: gl.issueBoards.BoardsStore.state, state: Store.state,
loading: true, loading: true,
endpoint: $boardApp.data('endpoint'), endpoint: $boardApp.dataset.endpoint,
disabled: $boardApp.data('disabled'), disabled: $boardApp.dataset.disabled === 'true',
issueLinkBase: $boardApp.data('issue-link-base') issueLinkBase: $boardApp.dataset.issueLinkBase
}, },
init () { init () {
gl.issueBoards.BoardsStore.create(); gl.issueBoards.BoardsStore.create();
...@@ -35,21 +36,16 @@ $(() => { ...@@ -35,21 +36,16 @@ $(() => {
created () { created () {
this.loading = true; this.loading = true;
gl.boardService = new BoardService(this.endpoint); gl.boardService = new BoardService(this.endpoint);
$boardApp
.removeAttr('data-endpoint')
.removeAttr('data-disabled')
.removeAttr('data-issue-link-base');
}, },
ready () { ready () {
gl.issueBoards.BoardsStore.disabled = this.disabled; Store.disabled = this.disabled;
gl.boardService.all() gl.boardService.all()
.then((resp) => { .then((resp) => {
const boards = resp.json(); const boards = resp.json();
for (let i = 0, boardsLength = boards.length; i < boardsLength; i++) { for (let i = 0, boardsLength = boards.length; i < boardsLength; i++) {
const board = boards[i], const board = boards[i],
list = gl.issueBoards.BoardsStore.addList(board); list = Store.addList(board);
if (list.type === 'done') { if (list.type === 'done') {
list.position = Infinity; list.position = Infinity;
...@@ -58,7 +54,7 @@ $(() => { ...@@ -58,7 +54,7 @@ $(() => {
} }
} }
gl.issueBoards.BoardsStore.addBlankState(); Store.addBlankState();
this.loading = false; this.loading = false;
}); });
} }
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
//= require ./board_list //= require ./board_list
(() => { (() => {
const Store = gl.issueBoards.BoardsStore;
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {}; window.gl.issueBoards = window.gl.issueBoards || {};
...@@ -20,7 +22,7 @@ ...@@ -20,7 +22,7 @@
data () { data () {
return { return {
query: '', query: '',
filters: gl.issueBoards.BoardsStore.state.filters filters: Store.state.filters
}; };
}, },
watch: { watch: {
...@@ -75,8 +77,8 @@ ...@@ -75,8 +77,8 @@
$board.$destroy(true); $board.$destroy(true);
this.$nextTick(() => { this.$nextTick(() => {
gl.issueBoards.BoardsStore.state.lists.splice(e.newIndex, 0, list); Store.state.lists.splice(e.newIndex, 0, list);
gl.issueBoards.BoardsStore.moveList(list, order); Store.moveList(list, order);
}); });
} }
} }
...@@ -89,7 +91,7 @@ ...@@ -89,7 +91,7 @@
this.sortable = Sortable.create(this.$el.parentNode, options); this.sortable = Sortable.create(this.$el.parentNode, options);
}, },
beforeDestroy () { beforeDestroy () {
gl.issueBoards.BoardsStore.state.lists.$remove(this.list); Store.state.lists.$remove(this.list);
} }
}); });
})(); })();
(() => { (() => {
const Store = gl.issueBoards.BoardsStore;
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {}; window.gl.issueBoards = window.gl.issueBoards || {};
...@@ -15,12 +17,12 @@ ...@@ -15,12 +17,12 @@
}, },
methods: { methods: {
addDefaultLists () { addDefaultLists () {
gl.issueBoards.BoardsStore.removeBlankState(); Store.removeBlankState();
for (let i = 0, labelsLength = this.predefinedLabels.length; i < labelsLength; i++) { for (let i = 0, labelsLength = this.predefinedLabels.length; i < labelsLength; i++) {
const label = this.predefinedLabels[i]; const label = this.predefinedLabels[i];
gl.issueBoards.BoardsStore.addList({ Store.addList({
title: label.title, title: label.title,
position: i, position: i,
list_type: 'label', list_type: 'label',
...@@ -39,7 +41,7 @@ ...@@ -39,7 +41,7 @@
for (let i = 0, dataLength = data.length; i < dataLength; i++) { for (let i = 0, dataLength = data.length; i < dataLength; i++) {
const listObj = data[i], const listObj = data[i],
list = gl.issueBoards.BoardsStore.findList('title', listObj.title); list = Store.findList('title', listObj.title);
list.id = listObj.id; list.id = listObj.id;
list.label.id = listObj.label.id; list.label.id = listObj.label.id;
...@@ -48,7 +50,7 @@ ...@@ -48,7 +50,7 @@
}); });
}, },
clearBlankState () { clearBlankState () {
gl.issueBoards.BoardsStore.removeBlankState(); Store.removeBlankState();
} }
} }
}); });
......
(() => { (() => {
const Store = gl.issueBoards.BoardsStore;
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {}; window.gl.issueBoards = window.gl.issueBoards || {};
...@@ -13,19 +15,19 @@ ...@@ -13,19 +15,19 @@
methods: { methods: {
filterByLabel (label, e) { filterByLabel (label, e) {
let labelToggleText = label.title; let labelToggleText = label.title;
const labelIndex = gl.issueBoards.BoardsStore.state.filters['label_name'].indexOf(label.title); const labelIndex = Store.state.filters['label_name'].indexOf(label.title);
$(e.target).tooltip('hide'); $(e.target).tooltip('hide');
if (labelIndex === -1) { if (labelIndex === -1) {
gl.issueBoards.BoardsStore.state.filters['label_name'].push(label.title); Store.state.filters['label_name'].push(label.title);
$('.labels-filter').prepend(`<input type="hidden" name="label_name[]" value="${label.title}" />`); $('.labels-filter').prepend(`<input type="hidden" name="label_name[]" value="${label.title}" />`);
} else { } else {
gl.issueBoards.BoardsStore.state.filters['label_name'].splice(labelIndex, 1); Store.state.filters['label_name'].splice(labelIndex, 1);
labelToggleText = gl.issueBoards.BoardsStore.state.filters['label_name'][0]; labelToggleText = Store.state.filters['label_name'][0];
$(`.labels-filter input[name="label_name[]"][value="${label.title}"]`).remove(); $(`.labels-filter input[name="label_name[]"][value="${label.title}"]`).remove();
} }
const selectedLabels = gl.issueBoards.BoardsStore.state.filters['label_name']; const selectedLabels = Store.state.filters['label_name'];
if (selectedLabels.length === 0) { if (selectedLabels.length === 0) {
labelToggleText = 'Label'; labelToggleText = 'Label';
} else if (selectedLabels.length > 1) { } else if (selectedLabels.length > 1) {
...@@ -34,7 +36,7 @@ ...@@ -34,7 +36,7 @@
$('.labels-filter .dropdown-toggle-text').text(labelToggleText); $('.labels-filter .dropdown-toggle-text').text(labelToggleText);
gl.issueBoards.BoardsStore.updateFiltersUrl(); Store.updateFiltersUrl();
} }
} }
}); });
......
//= require ./board_card //= require ./board_card
(() => { (() => {
const Store = gl.issueBoards.BoardsStore;
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {}; window.gl.issueBoards = window.gl.issueBoards || {};
...@@ -18,7 +20,7 @@ ...@@ -18,7 +20,7 @@
data () { data () {
return { return {
scrollOffset: 250, scrollOffset: 250,
filters: gl.issueBoards.BoardsStore.state.filters filters: Store.state.filters
}; };
}, },
watch: { watch: {
...@@ -59,20 +61,19 @@ ...@@ -59,20 +61,19 @@
onStart: (e) => { onStart: (e) => {
const card = this.$refs.issue[e.oldIndex]; const card = this.$refs.issue[e.oldIndex];
gl.issueBoards.BoardsStore.moving.issue = card.issue; Store.moving.issue = card.issue;
gl.issueBoards.BoardsStore.moving.list = card.list; Store.moving.list = card.list;
}, },
onAdd: (e) => { onAdd: (e) => {
const card = e.item, const fromList = Store.moving.list,
fromList = gl.issueBoards.BoardsStore.moving.list, issue = Store.moving.issue;
issue = gl.issueBoards.BoardsStore.moving.issue;
gl.issueBoards.BoardsStore.moveIssueToList(fromList, this.list, issue); gl.issueBoards.BoardsStore.moveIssueToList(fromList, this.list, issue);
}, },
onRemove (e) { onRemove (e) {
const card = e.item, const card = e.item,
list = gl.issueBoards.BoardsStore.moving.list, list = Store.moving.list,
issue = gl.issueBoards.BoardsStore.moving.issue; issue = Store.moving.issue;
// Remove the new dom element & let vue add the element // Remove the new dom element & let vue add the element
card.parentNode.removeChild(card); card.parentNode.removeChild(card);
......
$(() => { $(() => {
const Store = gl.issueBoards.BoardsStore;
$('.js-new-board-list').each(function () { $('.js-new-board-list').each(function () {
const $this = $(this); const $this = $(this);
...@@ -13,7 +15,7 @@ $(() => { ...@@ -13,7 +15,7 @@ $(() => {
}); });
}, },
renderRow (label) { renderRow (label) {
const active = gl.issueBoards.BoardsStore.findList('title', label.title), const active = Store.findList('title', label.title),
$li = $('<li />',), $li = $('<li />',),
$a = $('<a />', { $a = $('<a />', {
class: (active ? `is-active js-board-list-${active.id}` : ''), class: (active ? `is-active js-board-list-${active.id}` : ''),
...@@ -35,10 +37,10 @@ $(() => { ...@@ -35,10 +37,10 @@ $(() => {
clicked (label, $el, e) { clicked (label, $el, e) {
e.preventDefault(); e.preventDefault();
if (!gl.issueBoards.BoardsStore.findList('title', label.title)) { if (!Store.findList('title', label.title)) {
gl.issueBoards.BoardsStore.new({ Store.new({
title: label.title, title: label.title,
position: gl.issueBoards.BoardsStore.state.lists.length - 2, position: Store.state.lists.length - 2,
list_type: 'label', list_type: 'label',
label: { label: {
id: label.id, id: label.id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment