02/03: les tags sont maintenant des tableaux (et pas des string spliter si besoin)
This is an automated email from the git hooks/post-receive script. New commit to branch bow-v2-go in repository bow. See https://gitlab.nuiton.org/chorem/bow.git commit f9dc98cb8181dae0d7a2c57f9e9dc073d4cb998a Author: Benjamin <poussin@codelutin.com> Date: Thu May 21 00:32:07 2020 +0200 les tags sont maintenant des tableaux (et pas des string spliter si besoin) --- pkg/http/bookmarkResource.go | 4 +-- pkg/repository/bookmarkRepository.go | 18 +++++----- web/src/components/SearchInput.vue | 66 ++++++++++++++++++++++-------------- web/src/views/Home.vue | 34 ++++++++++++------- 4 files changed, 73 insertions(+), 49 deletions(-) diff --git a/pkg/http/bookmarkResource.go b/pkg/http/bookmarkResource.go index 05737cb..3ce52a8 100644 --- a/pkg/http/bookmarkResource.go +++ b/pkg/http/bookmarkResource.go @@ -20,7 +20,7 @@ func getBookmarks(w http.ResponseWriter, r *http.Request) { queryParams := r.URL.Query() id := queryParams.Get(constant.ID) uri := queryParams.Get(constant.URI) - tags := queryParams.Get(constant.Tags) + tags := queryParams[constant.Tags] fulltext := queryParams.Get(constant.Fulltext) log.Println("query: ", queryParams) @@ -53,7 +53,7 @@ func getBookmark(w http.ResponseWriter, r *http.Request) { currentUser := r.Context().Value(constant.User).(model.BowUser) id := mux.Vars(r)["id"] - json, err := repository.BookmarkJSON(currentUser, id, "", "", "", "", false, 0) + json, err := repository.BookmarkJSON(currentUser, id, "", []string{}, "", "", false, 0) if err != nil { utils.Throw(w, err) return diff --git a/pkg/repository/bookmarkRepository.go b/pkg/repository/bookmarkRepository.go index 978e8e5..0782cfc 100644 --- a/pkg/repository/bookmarkRepository.go +++ b/pkg/repository/bookmarkRepository.go @@ -19,7 +19,7 @@ si id est non vide alors fait une recherche exact sur l'id si uri est non vide alors fait une recherche exact sur l'uri sinon fait une recherche sur les critères: tags, fulltext */ -func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags string, fulltext string, orderBy string, orderDesc bool, first int) (string, error) { +func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags []string, fulltext string, orderBy string, orderDesc bool, first int) (string, error) { var result string var err error @@ -47,10 +47,10 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags string, q := &query{sql: `WITH __all AS (select * from bookmark where uri=$1) SELECT json_agg(__all.*) as j FROM __all`} result, err = q.QueryString(currentUser, uri) } else { - tagsJoined := strings.Join(strings.Fields(tags), ",") + tagsJoined := strings.Join(tags, ",") q := &query{sql: fmt.Sprintf(`WITH __query AS (select * from bookmark where tags @> string_to_array($1, ',')), - __info AS (select %[3]d as first, %[4]d as limit, count(id) as total, '%[1]s' as orderby, to_json('%[2]s' = 'desc') as orderdesc, $2::TEXT as tags, $3::TEXT as fulltext from __query), + __info AS (select %[3]d as first, %[4]d as limit, count(id) as total, '%[1]s' as orderby, to_json('%[2]s' = 'desc') as orderdesc, string_to_array($1, ',') as tags, $2::TEXT as fulltext from __query), __infoJson AS (select row_to_json(i.*) as info from __info i), __allTags AS (select unnest(tags) as tag from __query), __tags AS (select tag, count(tag) from __allTags group by tag order by 2 desc), @@ -59,7 +59,7 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags string, __jsonResult AS (SELECT json_agg(r.*) as result FROM __result r) select row_to_json(v) from (select * from __infoJson, __jsonTags, __jsonResult) v; `, orderBy, orderDirection, first, maxResult)} - result, err = q.QueryString(currentUser, tagsJoined, tags, fulltext) + result, err = q.QueryString(currentUser, tagsJoined, fulltext) } if err != nil { @@ -73,17 +73,17 @@ func BookmarkJSON(currentUser model.BowUser, id string, uri string, tags string, RenameTag renomme ou supprime un tag si newName est vide */ func RenameTag(currentUser model.BowUser, oldName string, newName string) (int64, error) { - tagArray := "{" + oldName + "}" + // tagArray := "{" + oldName + "}" var q *query var count int64 var err error if newName == "" { - q = &query{sql: `UPDATE bookmark SET tags=array_remove(tags, $2) where tags @> $1::text[]`} - count, err = q.execOnNRow(currentUser, tagArray, oldName) + q = &query{sql: `UPDATE bookmark SET tags=array_remove(tags, $2) where tags @> ARRAY[$1]`} + count, err = q.execOnNRow(currentUser, oldName, oldName) } else { - q = &query{sql: `UPDATE bookmark SET tags=array_replace(tags, $2, $3) where tags @> $1::text[]`} - count, err = q.execOnNRow(currentUser, tagArray, oldName, newName) + q = &query{sql: `UPDATE bookmark SET tags=array_replace(tags, $2, $3) where tags @> ARRAY[$1]`} + count, err = q.execOnNRow(currentUser, oldName, oldName, newName) } if err != nil { return 0, utils.NewHTTPError500(err, currentUser) diff --git a/web/src/components/SearchInput.vue b/web/src/components/SearchInput.vue index 775fee5..a1c559b 100644 --- a/web/src/components/SearchInput.vue +++ b/web/src/components/SearchInput.vue @@ -1,39 +1,33 @@ <template> <div class="search"> <form @submit.prevent="search"> - <div> + <label> tags: - <input type="text" v-model="mTags" @keyup.enter="search" /> - </div> - <div> + <TagsInput id="tags" :selected="mTags" :noCreation="true" @keyup.enter="search"></TagsInput> + </label> + <label> fulltext: <input type="text" v-model="mFulltext" @keyup.enter="search" /> - </div> + </label> </form> <form @submit.prevent="action"> - <div> + <label> web: <input type="text" v-model="mQuery" @keyup.enter="action" /> - </div> + </label> </form> </div> </template> <script> import { Component, Vue, Watch } from 'vue-property-decorator' +import TagsInput from '@/components/common/TagsInput' @Component({ name: 'SearchInput', - components: {} + components: { TagsInput } }) class SearchInput extends Vue { - tags = '' - fulltext = '' - query = '' - orderby = 'creationdate' - orderdesc = false - first = 0 - mTags = '' mFulltext = '' mQuery = '' @@ -67,6 +61,7 @@ class SearchInput extends Vue { this.mOrderby && (query.orderBy = this.mOrderby) this.mOrderdesc && (query.orderDesc = this.mOrderdesc) this.mFulltext && (query.first = this.mFirst) + console.log("XXXX Query", query) this.$router.push({ name: 'Home', query }) } } @@ -75,15 +70,37 @@ class SearchInput extends Vue { console.log('search', this.mQuery) } + get tags() { + const tags = this.$route.query.tags + if (!tags) { + return [] + } + + return Array.isArray(tags) ? [...tags] : [tags] + } + + get fulltext() { + return this.$route.query.fulltext + } + + get query() { + return this.$route.query.query + } + + get orderby() { + return this.$route.query.orderby || 'creationdate' + } + + get orderdesc() { + return this.$route.query.orderdesc || false + } + + get first() { + return this.$route.query.first || 0 + } + update(route) { - this.tags = route.query.tags - this.fulltext = route.query.fulltext - this.query = route.query.query - this.orderby = route.query.orderby - this.orderdesc = route.query.orderdesc - this.first = route.query.first - - this.mTags = this.tags || '' + this.mTags = this.tags this.mFulltext = this.fulltext || '' this.mQuery = this.query || '' this.mOrderby = this.orderby || '' @@ -96,7 +113,6 @@ class SearchInput extends Vue { console.log('onRouteChange SearchInput', to, from) this.update(to) } - } export default SearchInput @@ -116,4 +132,4 @@ form { input { width: 100px; } -</style> \ No newline at end of file +</style> diff --git a/web/src/views/Home.vue b/web/src/views/Home.vue index a6008e9..541995e 100644 --- a/web/src/views/Home.vue +++ b/web/src/views/Home.vue @@ -3,16 +3,15 @@ <div>{{ errorMsg }}</div> <CloudTags></CloudTags> <div class="navigation"> - <button><<</button> <button><</button> - {{ 1 + queryResponse.first }}-{{ queryResponse.first + queryResponse.limit }} - <button>></button> <button>>></button> / {{ queryResponse.total }} + <button><<</button> + <button><</button> + {{ 1 + queryResponse.info.first }}-{{ queryResponse.info.first + queryResponse.info.limit }} + <button>></button> + <button>>></button> + / {{ queryResponse.info.total }} </div> <div class="bookmarks-list"> - <Bookmark - v-for="bookmark in bookmarks" - :key="bookmark.id" - :bookmark="bookmark" - ></Bookmark> + <Bookmark v-for="bookmark in bookmarks" :key="bookmark.id" :bookmark="bookmark"></Bookmark> </div> </div> </template> @@ -37,7 +36,7 @@ class Home extends Vue { @Prop orderdesc @Prop first - mTags = this.tags || '' + mTags = this.forceArrayTags(this.tags) mFulltext = this.fulltext || '' mQuery = this.query || '' mOrderby = this.orderby || '' @@ -45,15 +44,24 @@ class Home extends Vue { mFirst = this.first || 0 errorMsg = '' - queryResponse = {} + queryResponse = {info:{}, tags:{}, result: {}} + get bookmarks() { return this.queryResponse.result } + forceArrayTags(tags) { + if (!tags) { + return [] + } + + return Array.isArray(tags) ? [...tags] : [tags] + } + fetchBookmark() { let searchParams = new URLSearchParams() this.id && searchParams.append('id', this.id) - this.mTags && searchParams.append('tags', this.mTags) + this.mTags && this.mTags.forEach((t) => searchParams.append('tags', t)) this.mFulltext && searchParams.append('fulltext', this.mFulltext) this.mQuery && searchParams.append('query', this.mQuery) this.mOrderby && searchParams.append('orderby', this.mOrderby) @@ -61,11 +69,11 @@ class Home extends Vue { this.mFirst && searchParams.append('first', this.mFirst) this.$fetch.get(`/bookmarks?${searchParams.toString()}`).then( - data => { + (data) => { this.queryResponse = data this.$store.commit('queryResponse', data) }, - err => { + (err) => { this.errorMsg = err.cause } ) -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm