diff --git a/VERSION b/VERSION index b1b25a5ffae43c2f07d222b53240d871e7c1789b..276cbf9e2858c779297bb9f73b34170302949ec4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.2 +2.3.0 diff --git a/lib/PZ/Controller/Shortcut.pm b/lib/PZ/Controller/Shortcut.pm index 87327b0b94845309a8194a2f10f397d583215002..6787f93116e061357012cab29b34ab687e1d0cfc 100644 --- a/lib/PZ/Controller/Shortcut.pm +++ b/lib/PZ/Controller/Shortcut.pm @@ -72,7 +72,7 @@ sub create ($c) { $c->render( status => 201, - openapi => { id => $shortcut->id }, + openapi => { $shortcut->get_columns }, ); } @@ -103,7 +103,7 @@ sub list ($c) { SHORTCUT: foreach my $shortcut ( $c->user->shortcuts( { deleted => undef }, - { order_by => 'shortcut' }, + { order_by => {-desc => 'created'} }, ) ) { push @shortcuts, $c->spec_filter( { $shortcut->get_columns }, 'Shortcut' diff --git a/openapi.yaml b/openapi.yaml index 9294a498c5186f0e2f96da39aff9b7ffea6a15c6..cc8b71bd9a760339fb1180ccec5d208cf8e4f336 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -27,6 +27,9 @@ components: type: integer readOnly: true maxLength: 8 + created: + type: string + description: Datum přidání shortcut: type: string description: Zkratka @@ -91,6 +94,10 @@ paths: responses: 201: description: Shortcut created + content: + application/json: + schema: + $ref: '#/components/schemas/Shortcut' get: tags: - shortcuts diff --git a/templates/shortcuts.html.ep b/templates/shortcuts.html.ep index 60f043bd5c7d90ead28abdd2549e8e38a6f55b99..8c580ca0e4faa36132140c4616dde4b86a951e76 100644 --- a/templates/shortcuts.html.ep +++ b/templates/shortcuts.html.ep @@ -32,6 +32,7 @@ <thead> <tr> <th class="text-left">Zkratka</th> + <th class="text-left">Přidano</th> <th class="text-left">URL</th> <th class="text-left">Přesměrování</th> <th class="text-left">Kliky</th> @@ -41,6 +42,7 @@ <tbody> <tr v-for="shortcut in shortcuts" > <td class="text-bold w-32" @click="showEdit(shortcut)" >{{shortcut.shortcut}}</td> + <td class="text-bold w-32" @click="showEdit(shortcut)" >{{ formatTimestamp(shortcut.created) }}</td> <td v-bind:title="shortcut.url" @click="showEdit(shortcut)" >{{ stripURL(shortcut.url) }}</td> <td class="w-24" @click="showEdit(shortcut)">{{ shortcut.code == 301 ? '301 trvalé' : '302 dočasné'}}</td> <td class="w-16 text-right" @click="showEdit(shortcut)">{{shortcut.counter}}</td> @@ -144,6 +146,7 @@ </div> <script type="module"> + const MAX_URL_LENGTH = 50; const BASE_URL = "/api/shortcuts"; const API_HEADERS = { "Content-Type": "application/json", @@ -185,8 +188,11 @@ }) .then( response => { if ( response.status == 201 ) { - this.shortcut = {} + this.shortcut = {}; app.fetchData(); + response.json().then(json => { + this.showInfo(json) + }) } else { response.json().then(json => { @@ -238,10 +244,15 @@ }, stripURL: function(url) { - const urlObj = new URL(url); - urlObj.search = ''; - urlObj.hash = ''; - return urlObj.toString(); + if ( url.length > MAX_URL_LENGTH ) { + url = url.substring(0, MAX_URL_LENGTH) + '...'; + } + return url; + }, + + formatTimestamp: function(timestamp) { + timestamp = new Date(timestamp); + return timestamp.toLocaleDateString('cs-CZ'); }, showDelete: function(shortcut) { @@ -250,7 +261,6 @@ }, showInfo: function(shortcut) { - this.selectedShortcut = shortcut; this.selectedShortcut.full_url = 'https://<%= config->{domain} %>/'+ shortcut.shortcut ; this.shortcutInfoVisible = true; navigator.clipboard.writeText(this.selectedShortcut.full_url);