Features.vue 4.64 KB
Newer Older
1
2
3
4
5
6
7
<template>
<v-container grid-list-md>
  <v-layout row wrap>
    <v-flex xs12>
      <h3>{{header}}</h3>
    </v-flex>

Markus Opolka's avatar
Markus Opolka committed
8
9
10
11
12
13
14
15
16
17
    <!-- <v-flex xs12> -->
    <!--   <v-select -->
    <!--     v-bind:items="letters" -->
    <!--     v-model="e1" -->
    <!--     label="Select" -->
    <!--     single-line -->
    <!--     bottom -->
    <!--     prepend-icon="local_post_office" -->
    <!--     ></v-select> -->
    <!-- </v-flex> -->
18

Markus Opolka's avatar
Markus Opolka committed
19
    <!-- Input Fields for Search -->
20
    <v-flex xs12 md3>
21
22
23
      <v-text-field
        v-model="feature_category"
        type="text" label="Category"
24
        @keyup.enter.native="validate">
25
      </v-text-field>
26
    </v-flex>
27
    <v-flex xs12 md3>
28
29
30
31
      <v-text-field
        v-model="feature_type"
        type="text"
        label="Type"
32
        @keyup.enter.native="validate">
33
      </v-text-field>
34
    </v-flex>
35
    <v-flex xs12 md3>
36
37
38
39
      <v-text-field
        v-model="feature_subtype"
        type="text"
        label="Subtype"
40
        @keyup.enter.native="validate">
41
      </v-text-field>
42
43
    </v-flex>

Markus Opolka's avatar
Markus Opolka committed
44
    <!-- Search Buttons -->
45
46
47
48
49
    <v-flex xs12 md3>
      <v-btn @click="validate" color="blue-grey darken-2" class="white--text">Search</v-btn>
      <v-btn @click="clear" color="blue-grey darken-2" class="white--text">Clear</v-btn>
    </v-flex>

Markus Opolka's avatar
Markus Opolka committed
50
    <!-- Invalid Search Warning -->
51
    <v-flex xs12>
52
53
54
      <v-alert outline color="lime darken-2" icon="warning" :value="invalid">
        Invalid Search - Please enter at least one parameter
      </v-alert>
55
56
57
58
59
60
61
    </v-flex>

    <!-- Progress Bar -->
    <v-flex xs12 v-if="searching">
      <v-progress-linear indeterminate color="primary"></v-progress-linear>
    </v-flex>

Markus Opolka's avatar
Markus Opolka committed
62
    <!-- Search Results Meta -->
63
64
65
    <v-flex xs12 v-if="results">
      <v-card color="blue-grey lighten-1" class="white--text">
        <v-card-text>
66
          Results: {{results.length}} letter(s) - {{countedHits}} hit(s)
67
68
69
70
        </v-card-text>
      </v-card>
    </v-flex>

Markus Opolka's avatar
Markus Opolka committed
71
    <!-- Search Results -->
Markus Opolka's avatar
Markus Opolka committed
72
73
74
    <v-flex xs12 v-if="results">
      <v-card v-for="letter in results" v-bind:key="letter.url">
        <v-card-title primary-title>
75
76
77
78
79
80
81
          <div class="title">
            {{letter.name}} - {{letter.collection}}
          <v-chip color="indigo" text-color="white">
            <v-avatar class="indigo darken-4">{{letter.count}}</v-avatar>
            Hits
          </v-chip>
          </div>
Markus Opolka's avatar
Markus Opolka committed
82
83
        </v-card-title>
        <v-card-text>
84
          <ul style="list-style-type:none;">
Markus Opolka's avatar
Markus Opolka committed
85
86
87
88
            <li v-for="hit in letter.results">
               <v-chip outline small color="secondary">{{hit._text}}</v-chip>
               <v-chip label small v-if="showlabels">{{(hit._attributes)}}</v-chip>
            </li>
Markus Opolka's avatar
Markus Opolka committed
89
90
91
          </ul>
        </v-card-text>
        <v-card-actions>
92
          <v-btn :to="letter.link" flat>View</v-btn>
Markus Opolka's avatar
Markus Opolka committed
93
94
95
96
        </v-card-actions>
      </v-card>
    </v-flex>

97
98
99
100
101
102
103
  </v-layout>
 </v-container>
</template>

<script>
export default {
  data () {
Markus Opolka's avatar
Markus Opolka committed
104
    // Search for Features in Letters
105
106
    return {
      header: 'Feature Search',
107
      invalid: false,
108
      searching: false,
109
110
111
      feature_category: '',
      feature_type: '',
      feature_subtype: '',
Markus Opolka's avatar
Markus Opolka committed
112
      results: null,
Markus Opolka's avatar
Markus Opolka committed
113
      showlabels: true,
114
115
116
117
118
119
120
      letters: [
        { text: 'All' }
      ]
    }
  },
  methods: {
    clear () {
Markus Opolka's avatar
Markus Opolka committed
121
      // Clears the search input fields
122
123
124
      this.feature_category = null
      this.feature_type = null
      this.feature_subtype = null
Markus Opolka's avatar
Markus Opolka committed
125
126
    },
    find () {
Markus Opolka's avatar
Markus Opolka committed
127
      // Call feature search API with parameters
Markus Opolka's avatar
Markus Opolka committed
128
129
130
131
132
133
134
135
136
      var params = {
        category: this.feature_category,
        type: this.feature_type,
        subtype: this.feature_subtype
      }

      // Remove undefined values
      Object.keys(params).forEach((key) => (params[key] == null) && delete params[key])
      this.searching = true
Markus Opolka's avatar
Markus Opolka committed
137
      this.$http.get('http://localhost:3000/api/features/', {params: params}).then(function (data) {
Markus Opolka's avatar
Markus Opolka committed
138
139
140
        this.results = data.body
        this.searching = false
      })
141
142
    },
    validate () {
Markus Opolka's avatar
Markus Opolka committed
143
      // Validate input fields and call find()
144
      var invalid = this.feature_category.length === 0 && this.feature_type.length === 0 && this.feature_subtype.length === 0
145
146
147
148
149
150
      if (invalid) {
        this.invalid = true
      } else {
        this.invalid = false
        this.find()
      }
151
152
    }
  },
153
154
  computed: {
    countedHits: function () {
Markus Opolka's avatar
Markus Opolka committed
155
      // Sums up all hits in all letters
156
157
158
159
160
161
162
      var hits = 0
      for (var value of this.results) {
        hits = hits + value.count
      }
      return hits
    }
  },
163
  created () {
Markus Opolka's avatar
Markus Opolka committed
164
    // Create list of all letters
165
166
167
168
169
170
171
172
    this.$http.get('http://localhost:3000/api/letters').then(function (data) {
      for (var value of data.body) {
        this.letters.push({text: value.name})
      }
    })
  }
}
</script>