Features.vue 4.5 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
85
          <ul style="list-style-type:none;">
            <li v-for="hit in letter.results">{{hit._text}} <v-chip label>{{(hit._attributes)}}</v-chip></li>
Markus Opolka's avatar
Markus Opolka committed
86
87
88
          </ul>
        </v-card-text>
        <v-card-actions>
89
          <v-btn :to="letter.link" flat>View</v-btn>
Markus Opolka's avatar
Markus Opolka committed
90
91
92
93
        </v-card-actions>
      </v-card>
    </v-flex>

94
95
96
97
98
99
100
  </v-layout>
 </v-container>
</template>

<script>
export default {
  data () {
Markus Opolka's avatar
Markus Opolka committed
101
    // Search for Features in Letters
102
103
    return {
      header: 'Feature Search',
104
      invalid: false,
105
      searching: false,
106
107
108
      feature_category: '',
      feature_type: '',
      feature_subtype: '',
Markus Opolka's avatar
Markus Opolka committed
109
      results: null,
110
111
112
113
114
115
116
      letters: [
        { text: 'All' }
      ]
    }
  },
  methods: {
    clear () {
Markus Opolka's avatar
Markus Opolka committed
117
      // Clears the search input fields
118
119
120
      this.feature_category = null
      this.feature_type = null
      this.feature_subtype = null
Markus Opolka's avatar
Markus Opolka committed
121
122
    },
    find () {
Markus Opolka's avatar
Markus Opolka committed
123
      // Call feature search API with parameters
Markus Opolka's avatar
Markus Opolka committed
124
125
126
127
128
129
130
131
132
      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
133
      this.$http.get('http://localhost:3000/api/features/', {params: params}).then(function (data) {
Markus Opolka's avatar
Markus Opolka committed
134
135
136
        this.results = data.body
        this.searching = false
      })
137
138
    },
    validate () {
Markus Opolka's avatar
Markus Opolka committed
139
      // Validate input fields and call find()
140
      var invalid = this.feature_category.length === 0 && this.feature_type.length === 0 && this.feature_subtype.length === 0
141
142
143
144
145
146
      if (invalid) {
        this.invalid = true
      } else {
        this.invalid = false
        this.find()
      }
147
148
    }
  },
149
150
  computed: {
    countedHits: function () {
Markus Opolka's avatar
Markus Opolka committed
151
      // Sums up all hits in all letters
152
153
154
155
156
157
158
      var hits = 0
      for (var value of this.results) {
        hits = hits + value.count
      }
      return hits
    }
  },
159
  created () {
Markus Opolka's avatar
Markus Opolka committed
160
    // Create list of all letters
161
162
163
164
165
166
167
168
    this.$http.get('http://localhost:3000/api/letters').then(function (data) {
      for (var value of data.body) {
        this.letters.push({text: value.name})
      }
    })
  }
}
</script>