11<template >
22 <div class =" collection-list" >
3- <table class =" table table-bordered table-hover table-sm" >
4- <thead class =" thead" >
5- <tr >
6- <th scope =" col" >ID</th >
7- <th scope =" col" >Name</th >
8- <th scope =" col" >Created</th >
9- <th scope =" col" >Completed</th >
10- <th scope =" col" >Status</th >
11- </tr >
12- </thead >
13- <tbody >
14- <tr v-for =" item in collections" v-bind:key =" item.id" @click =" view(item.id)" >
15- <th scope =" row" >{{ item.id }}</th >
16- <td class =" collection-name" >{{ item.name }}</td >
17- <td >{{ item.created_at | formatDateTime }}</td >
18- <td >{{ item.completed_at | formatDateTime }}</td >
19- <td >
20- <CollectionStatusBadge :status =" item.status" />
21- </td >
22- </tr >
23- </tbody >
24- </table >
25- <nav >
26- <ul class =" pagination" >
27- <li class =" page-item" >
28- <button class =" page-link" @click =" next('')" >Reload</button >
29- </li >
30- <li class =" page-item" v-if =" nextCursor" >
31- <button class =" page-link" @click =" next(nextCursor)" >Next</button >
32- </li >
33- </ul >
34- </nav >
3+ <template v-if =" error " >
4+ <b-alert show dismissible variant =" warning" >
5+ <h4 class =" alert-heading" >Search error</h4 >
6+ We couldn't connect to the API server. You may want to try again in a few seconds.
7+ <hr />
8+ <b-button @click =" retryButtonClicked" class =" m-1" >Retry</b-button >
9+ </b-alert >
10+ </template >
11+ <template v-else >
12+ <div >
13+ <b-form inline @submit =" onSubmit" @reset =" onReset" class =" py-3" >
14+ <b-input-group size =" sm" class =" w-100" >
15+ <b-form-input autofocus v-model =" query" type =" text" placeholder =" E.g.: a23bd138-4225-4cf7-845d-07a8983cf32f" ></b-form-input >
16+ <b-input-group-append >
17+ <b-button type =" submit" variant =" info" >Search</b-button >
18+ <b-button type =" reset" >Reset</b-button >
19+ </b-input-group-append >
20+ </b-input-group >
21+ </b-form >
22+ </div >
23+ <template v-if =" results .length > 0 " >
24+ <table class =" table table-bordered table-hover table-sm" >
25+ <thead class =" thead" >
26+ <tr >
27+ <th scope =" col" >ID</th >
28+ <th scope =" col" >Name</th >
29+ <th scope =" col" >Created</th >
30+ <th scope =" col" >Completed</th >
31+ <th scope =" col" >Status</th >
32+ </tr >
33+ </thead >
34+ <tbody >
35+ <tr v-for =" item in results" v-bind:key =" item.id" @click =" rowClicked(item.id)" >
36+ <th scope =" row" >{{ item.id }}</th >
37+ <td class =" collection-name" >{{ item.name }}</td >
38+ <td >{{ item.createdAt | formatDateTime }}</td >
39+ <td >{{ item.completedAt | formatDateTime }}</td >
40+ <td ><CollectionStatusBadge :status =" item.status" /></td >
41+ </tr >
42+ </tbody >
43+ </table >
44+ <nav >
45+ <ul class =" pagination" >
46+ <li class =" page-item" >
47+ <button class =" page-link" @click =" reloadButtonClicked" >Reload</button >
48+ </li >
49+ <li class =" page-item" v-if =" nextCursor" >
50+ <button class =" page-link" @click =" nextButtonClicked(nextCursor)" >Next</button >
51+ </li >
52+ </ul >
53+ </nav >
54+ </template >
55+ <div v-if =" results.length === 0" >
56+ No results.
57+ </div >
58+ </template >
3559 </div >
3660</template >
3761
3862<script lang="ts">
39- import { Component , Prop , Provide , Vue } from ' vue-property-decorator' ;
40- import { EnduroCollectionClient } from ' ../client' ;
63+ import { Component , Vue } from ' vue-property-decorator' ;
64+ import { namespace } from ' vuex-class' ;
65+ import { api , EnduroCollectionClient } from ' ../client' ;
4166import CollectionStatusBadge from ' @/components/CollectionStatusBadge.vue' ;
42- import { CollectionListRequest , CollectionListResponseBody , EnduroStoredCollectionResponseBodyCollection } from ' ../client/src' ;
67+ import * as CollectionStore from ' ../store/collection' ;
68+
69+ const collectionStoreNs = namespace (' collection' );
4370
4471@Component ({
4572 components: {
@@ -48,36 +75,85 @@ import { CollectionListRequest, CollectionListResponseBody, EnduroStoredCollecti
4875})
4976export default class CollectionList extends Vue {
5077
51- private interval: number = 0 ;
52- private collections: EnduroStoredCollectionResponseBodyCollection = [];
53- private nextCursor? : string = ' ' ;
78+ @collectionStoreNs .Getter (CollectionStore .GET_SEARCH_ERROR )
79+ private error? : boolean ;
80+
81+ @collectionStoreNs .Getter (CollectionStore .GET_SEARCH_RESULTS )
82+ private results: any ;
83+
84+ @collectionStoreNs .Getter (CollectionStore .GET_SEARCH_NEXT_CURSOR )
85+ private nextCursor: any ;
86+
87+ @collectionStoreNs .Action (CollectionStore .SEARCH_COLLECTIONS )
88+ private search: any ;
89+
90+ private query: string | null = null ;
5491
5592 private created() {
56- this .next ();
93+ this .search ();
94+ }
95+
96+ /**
97+ * Performs search action.
98+ *
99+ * @remarks
100+ * Search method for CollectionList. By default, it uses the cursor member of
101+ * the class.
102+ *
103+ * @param cursor - Optional cursor. Set to null to reset the cursor.
104+ */
105+ private doSearch(cursor ? : string | null ) {
106+ const attrs: any = {
107+ query: this .query ,
108+ cursor: typeof (cursor ) === ' undefined' ? this .nextCursor : cursor ,
109+ };
110+ this .search (attrs );
111+ }
112+
113+ /**
114+ * Perform same search re-using all existing state.
115+ */
116+ private retryButtonClicked() {
117+ this .doSearch ();
57118 }
58119
59- private load(cursor ? : string ) {
60- const request: CollectionListRequest = {};
61- if (cursor ) {
62- request .cursor = cursor ;
63- }
64- return EnduroCollectionClient .collectionList (request );
120+ /**
121+ * Perform search with the cursor reset.
122+ */
123+ private reloadButtonClicked() {
124+ this .doSearch (null );
65125 }
66126
67- private next( cursor ? : string ) {
68- this . load ( cursor ). then (( response : CollectionListResponseBody ) => {
69- this . collections = response . items ;
70- this . nextCursor = response . nextCursor ;
71- } );
127+ /* /
128+ * Perform search with a new cursor.
129+ */
130+ private nextButtonClicked( cursor : string ) {
131+ this . doSearch ( cursor );
72132 }
73133
74- private view(id : string ) {
75- this .$router .push ({
76- name: ' collection' ,
77- params: {id },
78- });
134+ /**
135+ * Perform search with the cursor reset.
136+ */
137+ private onSubmit(event : Event ) {
138+ event .preventDefault ();
139+ this .doSearch (null );
79140 }
80141
142+ /**
143+ * Perform search with both the query and cursor reset.
144+ */
145+ private onReset(event : Event ) {
146+ event .preventDefault ();
147+ this .query = null ;
148+ this .doSearch (null );
149+ }
150+
151+ /**
152+ * Forward user to the collection route.
153+ */
154+ private rowClicked(id : string ) {
155+ this .$router .push ({ name: ' collection' , params: {id } });
156+ }
81157}
82158 </script >
83159
0 commit comments