Commit 3b6ff7fc authored by Alfredo Sumaran's avatar Alfredo Sumaran

Add support to filter by name to Group list

parent 4c375338
...@@ -40,7 +40,6 @@ import Issue from './issue'; ...@@ -40,7 +40,6 @@ import Issue from './issue';
import BindInOut from './behaviors/bind_in_out'; import BindInOut from './behaviors/bind_in_out';
import Group from './group'; import Group from './group';
import GroupName from './group_name'; import GroupName from './group_name';
import GroupsList from './groups_list';
import ProjectsList from './projects_list'; import ProjectsList from './projects_list';
import MiniPipelineGraph from './mini_pipeline_graph_dropdown'; import MiniPipelineGraph from './mini_pipeline_graph_dropdown';
import BlobLinePermalinkUpdater from './blob/blob_line_permalink_updater'; import BlobLinePermalinkUpdater from './blob/blob_line_permalink_updater';
...@@ -148,12 +147,7 @@ const ShortcutsBlob = require('./shortcuts_blob'); ...@@ -148,12 +147,7 @@ const ShortcutsBlob = require('./shortcuts_blob');
case 'admin:projects:index': case 'admin:projects:index':
new ProjectsList(); new ProjectsList();
break; break;
case 'dashboard:groups:index':
new GroupsList();
break;
case 'explore:groups:index': case 'explore:groups:index':
new GroupsList();
const landingElement = document.querySelector('.js-explore-groups-landing'); const landingElement = document.querySelector('.js-explore-groups-landing');
if (!landingElement) break; if (!landingElement) break;
const exploreGroupsLanding = new Landing( const exploreGroupsLanding = new Landing(
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
*/ */
export default class FilterableList { export default class FilterableList {
constructor(form, filter, holder) { constructor(form, filter, holder, store) {
this.store = store;
this.filterForm = form; this.filterForm = form;
this.listFilterElement = filter; this.listFilterElement = filter;
this.listHolderElement = holder; this.listHolderElement = holder;
...@@ -33,7 +34,7 @@ export default class FilterableList { ...@@ -33,7 +34,7 @@ export default class FilterableList {
$(this.listHolderElement).fadeTo(250, 1); $(this.listHolderElement).fadeTo(250, 1);
}, },
success(data) { success(data) {
this.listHolderElement.innerHTML = data.html; this.store.setGroups(data);
// Change url so if user reload a page - search results are saved // Change url so if user reload a page - search results are saved
return window.history.replaceState({ return window.history.replaceState({
......
<script> <script>
import eventHub from '../event_hub';
export default { export default {
props: { props: {
groups: { groups: {
......
<script> <script>
import GroupsStore from '../stores/groups_store';
import GroupsService from '../services/groups_service';
import eventHub from '../event_hub';
export default { export default {
data() { props: {
const store = new GroupsStore(); groups: {
type: Array,
return { required: true,
store,
state: store.state,
};
},
created() {
const appEl = document.querySelector('#dashboard-group-app');
this.service = new GroupsService(appEl.dataset.endpoint);
this.fetchGroups();
eventHub.$on('toggleSubGroups', this.toggleSubGroups);
},
methods: {
fetchGroups() {
this.service.getGroups()
.then((response) => {
this.store.setGroups(response.json());
})
.catch(() => {
// TODO: Handler error
});
},
toggleSubGroups(group) {
GroupsStore.toggleSubGroups(group);
this.fetchGroups();
}, },
}, },
}; };
...@@ -43,6 +11,6 @@ export default { ...@@ -43,6 +11,6 @@ export default {
<template> <template>
<div> <div>
<group-folder :groups="state.groups" /> <group-folder :groups="groups" />
</div> </div>
</template> </template>
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
import Vue from 'vue'; import Vue from 'vue';
import GroupsList from '~/groups_list';
import GroupsComponent from './components/groups.vue'; import GroupsComponent from './components/groups.vue';
import GroupFolder from './components/group_folder.vue'; import GroupFolder from './components/group_folder.vue';
import GroupItem from './components/group_item.vue'; import GroupItem from './components/group_item.vue';
import GroupsStore from './stores/groups_store';
import GroupsService from './services/groups_service';
import eventHub from './event_hub';
$(() => { $(() => {
const appEl = document.querySelector('#dashboard-group-app'); const appEl = document.querySelector('#dashboard-group-app');
const form = document.querySelector('form#group-filter-form');
const filter = document.querySelector('.js-groups-list-filter');
const holder = document.querySelector('.js-groups-list-holder');
const store = new GroupsStore();
const service = new GroupsService(appEl.dataset.endpoint);
Vue.component('groups-component', GroupsComponent); Vue.component('groups-component', GroupsComponent);
Vue.component('group-folder', GroupFolder); Vue.component('group-folder', GroupFolder);
...@@ -14,6 +24,33 @@ $(() => { ...@@ -14,6 +24,33 @@ $(() => {
const GroupsApp = new Vue({ const GroupsApp = new Vue({
el: appEl, el: appEl,
render: createElement => createElement('groups-component'), data() {
return {
store,
state: store.state,
};
},
methods: {
fetchGroups() {
service.getGroups()
.then((response) => {
store.setGroups(response.json());
})
.catch(() => {
// TODO: Handler error
});
},
toggleSubGroups(group) {
GroupsStore.toggleSubGroups(group);
this.fetchGroups();
},
},
created() {
const groupFilterList = new GroupsList(form, filter, holder, store);
this.fetchGroups();
eventHub.$on('toggleSubGroups', this.toggleSubGroups);
},
}); });
}); });
...@@ -5,13 +5,9 @@ import FilterableList from './filterable_list'; ...@@ -5,13 +5,9 @@ import FilterableList from './filterable_list';
* Updates the html content of the page with the received one. * Updates the html content of the page with the received one.
*/ */
export default class GroupsList { export default class GroupsList {
constructor() { constructor(form, filter, holder, store) {
const form = document.querySelector('form#group-filter-form'); if (form && filter && holder && store) {
const filter = document.querySelector('.js-groups-list-filter'); const list = new FilterableList(form, filter, holder, store);
const holder = document.querySelector('.js-groups-list-holder');
if (form && filter && holder) {
const list = new FilterableList(form, filter, holder);
list.initSearch(); list.initSearch();
} }
} }
......
.js-groups-list-holder#dashboard-group-app{ data: { endpoint: dashboard_groups_path(format: :json) } } .js-groups-list-holder
#dashboard-group-app{ data: { endpoint: dashboard_groups_path(format: :json) } }
%groups-component{ ':groups' => 'state.groups' }
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