Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New timeline picker component #911

Merged
merged 2 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions timesketch/frontend/dist/js/app.e3835b2d.js

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions timesketch/frontend/src/components/SketchExplore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ limitations under the License.
</div>
</section>

<section class="section">
<div class="container">
<div class="card">
<div class="card-content">
<ts-sketch-explore-search :sketchId="sketchId"></ts-sketch-explore-search>
</div>
</div>
</div>
</section>
<ts-sketch-explore-search :sketchId="sketchId"></ts-sketch-explore-search>

<section class="section" v-if="searchInProgress">
<div class="container">
Expand Down
83 changes: 54 additions & 29 deletions timesketch/frontend/src/components/SketchExploreSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,79 @@ limitations under the License.
-->
<template>
<div>
<form v-on:submit.prevent="search">
<input v-model="currentQueryString" class="ts-search-input" type="text" placeholder="Search" autofocus>
</form>
<br>

<div class="modal" v-bind:class="{ 'is-active': showCreateViewModal }">>
<div class="modal-background"></div>
<div class="modal-content">
<section class="section">
<div class="container">
<div class="card">
<div class="card-content">

<form v-on:submit.prevent="search">
<input v-model="currentQueryString" class="ts-search-input" type="text" placeholder="Search" autofocus>
</form>
<br>

<div class="modal" v-bind:class="{ 'is-active': showCreateViewModal }">>
<div class="modal-background"></div>
<div class="modal-content">
<div class="card">
<header class="card-header">
<p class="card-header-title">Create new view</p>
</header>
<div class="card-content">
<div class="content">
<ts-create-view-form @toggleCreateViewModal="toggleCreateViewModal" :sketchId="sketchId" :currentQueryString="currentQueryString" :currentQueryFilter="currentQueryFilter"></ts-create-view-form>
</div>
</div>
</div>
</div>
<button class="modal-close is-large" aria-label="close" v-on:click="showCreateViewModal = !showCreateViewModal"></button>
</div>

<div class="field is-grouped">
<p class="control">
<ts-view-list-dropdown @setActiveView="searchView"></ts-view-list-dropdown>
</p>
<p class="control">
<a class="button" v-on:click="showCreateViewModal = !showCreateViewModal">
<span class="icon is-small">
<i class="fas fa-save"></i>
</span>
<span>Save view</span>
</a>
</p>
</div>
</div>
</div>
</div>
</section>

<section class="section">
<div class="container">
<div class="card">
<header class="card-header">
<p class="card-header-title">Create new view</p>
<p class="card-header-title">Timelines</p>
</header>
<div class="card-content">
<div class="content">
<ts-create-view-form @toggleCreateViewModal="toggleCreateViewModal" :sketchId="sketchId" :currentQueryString="currentQueryString" :currentQueryFilter="currentQueryFilter"></ts-create-view-form>
</div>
<ts-explore-timeline-picker @doSearch="search" v-if="sketch.active_timelines"></ts-explore-timeline-picker>
</div>
</div>
</div>
<button class="modal-close is-large" aria-label="close" v-on:click="showCreateViewModal = !showCreateViewModal"></button>
</div>

<div class="field is-grouped">
<p class="control">
<ts-view-list-dropdown @setActiveView="searchView"></ts-view-list-dropdown>
</p>
<p class="control">
<a class="button" v-on:click="showCreateViewModal = !showCreateViewModal">
<span class="icon is-small">
<i class="fas fa-save"></i>
</span>
<span>Save view</span>
</a>
</p>
</div>
</section>

</div>
</template>

<script>
import ApiClient from '../utils/RestApiClient'
import TsViewListDropdown from './SketchExploreViewListDropdown'
import TsCreateViewForm from './SketchCreateViewForm'
import TsExploreTimelinePicker from './SketchExploreTimelinePicker'

export default {
name: 'ts-sketch-explore-search',
components: {
TsViewListDropdown,
TsCreateViewForm
TsCreateViewForm,
TsExploreTimelinePicker
},
props: ['sketchId'],
data () {
Expand Down
92 changes: 92 additions & 0 deletions timesketch/frontend/src/components/SketchExploreTimelinePicker.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!--
Copyright 2019 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<template>
<div class="tags">
<span class="tag is-medium" style="cursor: pointer;"
v-bind:style="timelineColor(timeline)"
v-on:click="updateFilter(timeline)"
v-for="timeline in sketch.active_timelines" :key="timeline.id">
{{ timeline.name }}
</span>
</div>
</template>

<script>
export default {
name: 'ts-sketch-explore-timeline-picker',
computed: {
sketch () {
return this.$store.state.sketch
},
meta () {
return this.$store.state.meta
},
currentQueryFilter: {
get: function () {
return this.$store.state.currentQueryFilter
},
set: function (queryFilter) {
this.$store.commit('updateCurrentQueryFilter', queryFilter)
}
}
},
methods: {
toggleIndex: function (indexName) {
let newArray = this.currentQueryFilter.indices.slice()
let index = newArray.indexOf(indexName)
if (index === -1) {
newArray.push(indexName)
} else {
newArray.splice(index, 1)
}
return newArray
},
enableAllIndices: function () {
let allIndices = []
this.sketch.active_timelines.forEach(function (timeline) {
allIndices.push(timeline.searchindex.index_name)
})
this.currentQueryFilter.indices = allIndices
},
updateFilter: function (timeline) {
let indexName = timeline.searchindex.index_name
this.currentQueryFilter.indices = this.toggleIndex(indexName)
this.$emit('doSearch')
},
timelineColor (timeline) {
let indexName = timeline.searchindex.index_name
let color = timeline.color
if (!color.startsWith('#')) {
color = '#' + color
}
// Grey out the index if it is not selected.
if (!this.currentQueryFilter.indices.includes(indexName)) {
color = '#f5f5f5'
}
return {
'background-color': color
}
}
},
created: function () {
if (this.currentQueryFilter.indices.includes('_all')) {
this.enableAllIndices()
}
}
}
</script>

<style lang="scss"></style>