This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js: Namespaces#index refactoring w/ Vue
- Created custom elements for namespaces (namespace-panel, new-namespace-form, namespace-table, namespace-table-row, namespace-visibility) - Added sorting columns (similar to #590) - Fixed pagination (similar to #585) - Improved UX of changing namespace visibility (see gif below) - Updated slim gem - Updated active_model_serializers gem - Used serializers (check namespace_serializer.rb) for json rendering - Added moment for dates (kind of overkill but a good thing in the long term) - Added lodash and lodash babel plugin (makes partial imports possible) - And other minor changes
- Loading branch information
1 parent
ee387ff
commit 3e145dc
Showing
58 changed files
with
1,335 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/assets/javascripts/modules/namespaces/components/new-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Vue from 'vue'; | ||
|
||
import EventBus from '~/utils/eventbus'; | ||
|
||
import { setTypeahead } from '~/utils/typeahead'; | ||
|
||
import Alert from '~/shared/components/alert'; | ||
import FormMixin from '~/shared/mixins/form'; | ||
|
||
import NamespacesService from '../services/namespaces'; | ||
|
||
const TYPEAHEAD_INPUT = '.remote .typeahead'; | ||
|
||
const { set } = Vue; | ||
|
||
export default { | ||
template: '#js-new-namespace-form-tmpl', | ||
|
||
mixins: [FormMixin], | ||
|
||
data() { | ||
return { | ||
namespace: { | ||
namespace: {}, | ||
}, | ||
}; | ||
}, | ||
|
||
methods: { | ||
onSubmit() { | ||
NamespacesService.save(this.namespace).then((response) => { | ||
const namespace = response.data.data; | ||
const name = namespace.attributes.clean_name; | ||
|
||
this.toggleForm(); | ||
set(this.namespace, 'namespace', {}); | ||
|
||
Alert.show(`Namespace '${name}' was created successfully`); | ||
EventBus.$emit('namespaceCreated', namespace); | ||
}).catch((response) => { | ||
let errors = response.data; | ||
|
||
if (Array.isArray(errors)) { | ||
errors = errors.join('<br />'); | ||
} | ||
|
||
Alert.show(errors); | ||
}); | ||
}, | ||
}, | ||
|
||
mounted() { | ||
const $team = setTypeahead(TYPEAHEAD_INPUT, '/namespaces/typeahead/%QUERY'); | ||
|
||
// workaround because of typeahead | ||
$team.on('change', () => { | ||
set(this.namespace.namespace, 'team', $team.val()); | ||
}); | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
app/assets/javascripts/modules/namespaces/components/panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import LoadingIcon from '~/shared/components/loading-icon'; | ||
import ToggleLink from '~/shared/components/toggle-link'; | ||
import PanelWithFormMixin from '~/shared/mixins/panel-with-form'; | ||
|
||
import NamespacesTable from './table'; | ||
|
||
export default { | ||
template: '#js-namespaces-panel-tmpl', | ||
|
||
mixins: [PanelWithFormMixin], | ||
|
||
props: ['namespaces', 'tableSortable'], | ||
|
||
components: { | ||
LoadingIcon, | ||
NamespacesTable, | ||
ToggleLink, | ||
}, | ||
}; |
23 changes: 23 additions & 0 deletions
23
app/assets/javascripts/modules/namespaces/components/table-row.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import moment from 'moment'; | ||
|
||
import NamespaceVisibility from './visibility'; | ||
|
||
export default { | ||
template: '#js-namespace-table-row-tmpl', | ||
|
||
props: ['namespace'], | ||
|
||
computed: { | ||
scopeClass() { | ||
return `namespace_${this.namespace.id}`; | ||
}, | ||
|
||
createdAt() { | ||
return moment(this.namespace.attributes.created_at).format('MMMM DD, YYYY HH:mm'); | ||
}, | ||
}, | ||
|
||
components: { | ||
NamespaceVisibility, | ||
}, | ||
}; |
74 changes: 74 additions & 0 deletions
74
app/assets/javascripts/modules/namespaces/components/table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Vue from 'vue'; | ||
import getProperty from 'lodash/get'; | ||
|
||
import Comparator from '~/utils/comparator'; | ||
import TablePagination from '~/shared/components/table-pagination'; | ||
|
||
import NamespaceTableRow from './table-row'; | ||
|
||
const { set } = Vue; | ||
|
||
export default { | ||
template: '#js-namespaces-table-tmpl', | ||
|
||
props: ['namespaces', 'sortable'], | ||
|
||
components: { | ||
NamespaceTableRow, | ||
TablePagination, | ||
}, | ||
|
||
data() { | ||
return { | ||
sortAsc: true, | ||
sortBy: 'attributes.clean_name', | ||
limit: 3, | ||
currentPage: 1, | ||
}; | ||
}, | ||
|
||
computed: { | ||
offset() { | ||
return (this.currentPage - 1) * this.limit; | ||
}, | ||
|
||
filteredNamespaces() { | ||
const order = this.sortAsc ? 1 : -1; | ||
const sortedNamespaces = [...this.namespaces]; | ||
const sample = sortedNamespaces[0]; | ||
const value = getProperty(sample, this.sortBy); | ||
const comparator = Comparator.of(value); | ||
|
||
// sorting | ||
sortedNamespaces.sort((a, b) => { | ||
const aValue = getProperty(a, this.sortBy); | ||
const bValue = getProperty(b, this.sortBy); | ||
|
||
return order * comparator(aValue, bValue); | ||
}); | ||
|
||
// pagination | ||
const slicedNamespaces = sortedNamespaces.slice(this.offset, this.limit * this.currentPage); | ||
|
||
return slicedNamespaces; | ||
}, | ||
}, | ||
|
||
methods: { | ||
sort(attribute) { | ||
if (!this.sortable) { | ||
return; | ||
} | ||
|
||
// if sort column has changed, go always asc | ||
// inverse current order otherwise | ||
if (this.sortBy === attribute) { | ||
set(this, 'sortAsc', !this.sortAsc); | ||
} else { | ||
set(this, 'sortAsc', true); | ||
} | ||
|
||
set(this, 'sortBy', attribute); | ||
}, | ||
}, | ||
}; |
75 changes: 75 additions & 0 deletions
75
app/assets/javascripts/modules/namespaces/components/visibility.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Vue from 'vue'; | ||
|
||
import Alert from '~/shared/components/alert'; | ||
|
||
import NamespacesService from '../services/namespaces'; | ||
|
||
const { set } = Vue; | ||
|
||
export default { | ||
template: '#js-namespace-visibility-tmpl', | ||
|
||
props: ['namespace'], | ||
|
||
data() { | ||
return { | ||
onGoingRequest: false, | ||
newVisibility: null, | ||
}; | ||
}, | ||
|
||
computed: { | ||
isPrivate() { | ||
return this.namespace.attributes.visibility === 'visibility_private'; | ||
}, | ||
|
||
isProtected() { | ||
return this.namespace.attributes.visibility === 'visibility_protected'; | ||
}, | ||
|
||
isPublic() { | ||
return this.namespace.attributes.visibility === 'visibility_public'; | ||
}, | ||
|
||
canChangeVibisility() { | ||
return this.namespace.meta.can_change_visibility && | ||
!this.onGoingRequest; | ||
}, | ||
|
||
privateTitle() { | ||
if (this.namespace.attributes.global) { | ||
return 'The global namespace cannot be private'; | ||
} | ||
|
||
return 'Team members can pull images from this namespace'; | ||
}, | ||
}, | ||
|
||
methods: { | ||
showLoading(visibility) { | ||
return this.onGoingRequest && | ||
visibility === this.newVisibility; | ||
}, | ||
|
||
change(visibility) { | ||
const currentVisibility = this.namespace.attributes.visibility; | ||
|
||
if (visibility === currentVisibility) { | ||
return; | ||
} | ||
|
||
set(this, 'onGoingRequest', true); | ||
set(this, 'newVisibility', visibility); | ||
|
||
NamespacesService.changeVisibility(this.namespace.id, { visibility }).then(() => { | ||
set(this.namespace.attributes, 'visibility', visibility); | ||
Alert.show(`Visibility of '${this.namespace.attributes.clean_name}' namespace updated`); | ||
}).catch(() => { | ||
Alert.show('An error happened while updating namespace visibility'); | ||
}).finally(() => { | ||
set(this, 'onGoingRequest', false); | ||
set(this, 'newVisibility', null); | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.