ZoteroQueryComponent.vue 5.01 KB
Newer Older
Jerome Chauveau's avatar
Jerome Chauveau committed
1
2
<template>
    <div class="zotero-query-component">
3
        <h2>Zotero Client <a role="button" @click="isConfigVisible=!isConfigVisible" title="Afficher/masquer la configuration"></a></h2>
Jerome Chauveau's avatar
Jerome Chauveau committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
        <div class="zotero-config-pane" v-if="isConfigVisible">
            <div>
                <label>Type de collection</label>
                <select v-model="type">
                    <option value="group">Group</option>
                    <option value="user">User</option>
                </select>
            </div>

            <div>
                <label>Identifiant de "{{type}}"</label>
                <input v-model="groupOrUserID"/>
            </div>

            <div>
                <label>Résultats par page</label>
                <input type="number" v-model="pageLength"/>
            </div>

        </div>
        <div>
            <input v-model="textQuery"/>
            <button class="zotero-query-btn" @click="doQuery()" :disabled="!canQuery">
                <span>&#128269;</span>
            </button>
        </div>
        <progress v-if="isFetching"/>

        <template v-if="entries">
            <h3>Résultats <span class="results-count">{{nbResults}}</span></h3>
34
35
            <div class="zotero-pager">Page 
                <a role="button" class="next-prev-btn" :class="{'active': currentPage !== 1}" @click="previousPage()">&#5176;</a>
Jerome Chauveau's avatar
Jerome Chauveau committed
36
                <span>{{currentPage}}/{{getTotalPages}}</span>
37
                <a role="button" class="next-prev-btn" :class="{'active': currentPage !== getTotalPages}" @click="nextPage()">&#5171;</a>
Jerome Chauveau's avatar
Jerome Chauveau committed
38
39
40
            </div>
            <div class="zotero-entries">
                <ul>
41
42
43
44
45
46
                    <li class="zotero-entry" v-for="entry in entries" :key="'entry-' + entry.key">
                        <ul>
                            <li class="zotero-title">{{entry.data.title}}</li>
                            <li class="zotero-type">{{entry.data.itemType}}</li>
                            <li class="zotero-item-key">{{entry.key}}</li>
                        </ul>
Jerome Chauveau's avatar
Jerome Chauveau committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
                    </li>
                </ul>
            </div>
        </template>

    </div>
</template>

<script>
    const Zotero = require('libzotero');

    export default {
        name: 'ZoteroQueryComponent',
        props: {},
        data() {
            return {
                type: 'group',
                groupOrUserID: '427575',
                entries: null,
                isFetching: false,
67
                isConfigVisible: false,
Jerome Chauveau's avatar
Jerome Chauveau committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
                start:0,
                currentPage:1,
                pageLength: 10,
                nbResults: 0,
                textQuery : ""

            }
        },
        computed: {
            getTotalPages : function(){
                return Math.ceil(this.nbResults / this.pageLength)
            },

            canQuery : function(){
                return this.textQuery && this.textQuery.trim() !== ''
            }
        },
        methods: {
            doQuery() {
                this.isFetching = true;
                this.entries = null;
                let library = new Zotero.Library(this.type, this.groupOrUserID);
                library.loadItems({start: this.start, limit: this.pageLength, q: this.textQuery}).then((response)=>{
                    this.entries = response.data;
                    this.nbResults = response.totalResults;
                    this.isFetching = false;
                })
            },

            previousPage(){
                this.start -= this.pageLength;
                this.currentPage --;
                this.doQuery();
            },

            nextPage(){
                this.start += this.pageLength;
                this.currentPage ++;
                this.doQuery();
            }
        }


    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    * {
        --input-height: 34px;
    }

    input, button, select {
        height: var(--input-height);
    }

124
125
126
127
    h2 a:hover {
        color : darkgray;
    }

Jerome Chauveau's avatar
Jerome Chauveau committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    a[role=button], button{
        cursor: pointer;
    }

    label{
        display: inline-block;
        width: 200px;
    }

    .next-prev-btn{
        display: inline-block;
        margin-left: 15px;
        margin-right: 15px;
    }

    .zotero-entries ul{
        list-style-type: square;
145
146
        margin-bottom : 15px;
        padding-left: 15px;
Jerome Chauveau's avatar
Jerome Chauveau committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    }

    .results-count{
        font-size: 0.8em;
    }
    .results-count:before{
        content: ' (';
    }
    .results-count:after{
        content: ') ';
    }

    .zotero-config-pane{
        background-color: gainsboro;
        padding:15px;
        margin-bottom: 15px;
163
        font-size: 0.8em;
Jerome Chauveau's avatar
Jerome Chauveau committed
164
165
166
167
168
169
    }

    .zotero-query-btn{
        margin-left: 15px;
    }

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    .next-prev-btn {
        visibility: hidden;
    }
    .next-prev-btn.active{
        visibility: visible;
    }

    .zotero-entry ul{
        list-style-type: none;
    }

    .zotero-type{
        color: #888;
    }

    .zotero-title{
        font-style: italic;
    }

    .zotero-item-key{
        font-size: 0.7em;
    }
Jerome Chauveau's avatar
Jerome Chauveau committed
192
193

</style>