Features.vue 4.1 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

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

43
44
45
46
47
    <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>

48
    <v-flex xs12>
49
50
51
      <v-alert outline color="lime darken-2" icon="warning" :value="invalid">
        Invalid Search - Please enter at least one parameter
      </v-alert>
52
53
54
55
56
57
58
    </v-flex>

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

59
60
61
    <v-flex xs12 v-if="results">
      <v-card color="blue-grey lighten-1" class="white--text">
        <v-card-text>
62
          Results: {{results.length}} letter(s) - {{countedHits}} hit(s)
63
64
65
66
        </v-card-text>
      </v-card>
    </v-flex>

Markus Opolka's avatar
Markus Opolka committed
67
68
69
    <v-flex xs12 v-if="results">
      <v-card v-for="letter in results" v-bind:key="letter.url">
        <v-card-title primary-title>
70
71
72
73
74
75
76
          <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
77
78
        </v-card-title>
        <v-card-text>
79
80
          <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
81
82
83
          </ul>
        </v-card-text>
        <v-card-actions>
84
          <v-btn :to="letter.link" flat>View</v-btn>
Markus Opolka's avatar
Markus Opolka committed
85
86
87
88
        </v-card-actions>
      </v-card>
    </v-flex>

89
90
91
92
93
94
95
96
97
  </v-layout>
 </v-container>
</template>

<script>
export default {
  data () {
    return {
      header: 'Feature Search',
98
      invalid: false,
99
      searching: false,
100
101
102
      feature_category: '',
      feature_type: '',
      feature_subtype: '',
Markus Opolka's avatar
Markus Opolka committed
103
      results: null,
104
105
106
107
108
109
110
111
112
113
      letters: [
        { text: 'All' }
      ]
    }
  },
  methods: {
    clear () {
      this.feature_category = null
      this.feature_type = null
      this.feature_subtype = null
Markus Opolka's avatar
Markus Opolka committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    },
    find () {
      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
      this.$http.get('http://localhost:3000/api/feature/', {params: params}).then(function (data) {
        this.results = data.body
        this.searching = false
      })
129
130
    },
    validate () {
131
      var invalid = this.feature_category.length === 0 && this.feature_type.length === 0 && this.feature_subtype.length === 0
132
133
134
135
136
137
      if (invalid) {
        this.invalid = true
      } else {
        this.invalid = false
        this.find()
      }
138
139
    }
  },
140
141
142
143
144
145
146
147
148
  computed: {
    countedHits: function () {
      var hits = 0
      for (var value of this.results) {
        hits = hits + value.count
      }
      return hits
    }
  },
149
150
151
152
153
154
155
156
157
  created () {
    this.$http.get('http://localhost:3000/api/letters').then(function (data) {
      for (var value of data.body) {
        this.letters.push({text: value.name})
      }
    })
  }
}
</script>