Splitting Draft et Active bundles

This commit is contained in:
Axel 2023-05-17 13:54:58 +02:00
parent dc70bd9650
commit 47fa3cb3f3
Signed by: axel
GPG key ID: 73C0A5961B6BC740
3 changed files with 26 additions and 14 deletions

View file

@ -79,7 +79,6 @@ return [
'authentication' => 'Authentication', 'authentication' => 'Authentication',
'login' => 'Username', 'login' => 'Username',
'password' => 'Password', 'password' => 'Password',
'do-login' => 'Login now' 'do-login' => 'Login now',
'pending' => 'Drafts',
]; ];

View file

@ -79,7 +79,6 @@ return [
'authentication' => 'Authentification', 'authentication' => 'Authentification',
'login' => 'Identifiant', 'login' => 'Identifiant',
'password' => 'Mot de passe', 'password' => 'Mot de passe',
'do-login' => 'S\'authentifier' 'do-login' => 'S\'authentifier',
'pending' => 'Brouillons',
]; ];

View file

@ -6,8 +6,9 @@
document.addEventListener('alpine:init', () => { document.addEventListener('alpine:init', () => {
Alpine.data('bundle', () => ({ Alpine.data('bundle', () => ({
bundles: null, bundles: null,
active: null, pending: [],
expired: null, active: [],
expired: [],
currentBundle: null, currentBundle: null,
init: function() { init: function() {
@ -17,20 +18,25 @@
this.bundles = JSON.parse(bundles) this.bundles = JSON.parse(bundles)
if (this.bundles != null && Object.keys(this.bundles).length > 0) { if (this.bundles != null && Object.keys(this.bundles).length > 0) {
this.active = []
this.expired = []
this.bundles.forEach( (bundle) => { this.bundles.forEach( (bundle) => {
if (bundle.title == null || bundle.title == '') { if (bundle.title == null || bundle.title == '') {
bundle.title = 'untitled' bundle.label = 'untitled'
}
else {
bundle.label = bundle.title
} }
if (bundle.expires_at != null && moment.unix(bundle.expires_at).isBefore(moment())) { if (bundle.expires_at != null && moment.unix(bundle.expires_at).isBefore(moment())) {
this.expired.push(bundle) this.expired.push(bundle)
} }
else { else if (bundle.completed == true) {
this.active.push(bundle) this.active.push(bundle)
} }
else {
this.pending.push(bundle)
}
bundle.label += ' - {{ __('app.created-at') }} '+moment.unix(bundle.created_at).fromNow()
}) })
} }
@ -124,10 +130,18 @@
> >
<option>-</option> <option>-</option>
<template x-if="Object.keys(pending).length > 0">
<optgroup label="{{ __('app.pending') }}">
<template x-for="bundle in pending">
<option :value="bundle.bundle_id" x-text="bundle.label"></option>
</template>
</optgroup>
</template>
<template x-if="Object.keys(active).length > 0"> <template x-if="Object.keys(active).length > 0">
<optgroup label="{{ __('app.active') }}"> <optgroup label="{{ __('app.active') }}">
<template x-for="bundle in active"> <template x-for="bundle in active">
<option :value="bundle.bundle_id" x-text="bundle.title"></option> <option :value="bundle.bundle_id" x-text="bundle.label"></option>
</template> </template>
</optgroup> </optgroup>
</template> </template>
@ -135,7 +149,7 @@
<template x-if="Object.keys(expired).length > 0"> <template x-if="Object.keys(expired).length > 0">
<optgroup label="{{ __('app.expired') }}"> <optgroup label="{{ __('app.expired') }}">
<template x-for="bundle in expired"> <template x-for="bundle in expired">
<option :value="bundle.bundle_id" x-text="bundle.title"></option> <option :value="bundle.bundle_id" x-text="bundle.label"></option>
</template> </template>
</optgroup> </optgroup>
</template> </template>