You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

190 lines
5.4 KiB

<template>
<div class="row">
<div class="col-md-12">
<div class="float-end">
<div v-if="$store.state.notes.length > 0" class="filter-wrapper">
<a href="javascript:"
v-if="colorToFilter !== ''"
v-on:click="colorToFilter = ''"
class="color-change-button disable-filter-button"
:style="'background-color: '+colorToFilter">
Filter aus
</a>
<span v-for="color in noteColors"
v-bind:key="color">
<a href="javascript:"
v-if="colorToFilter !== color"
v-on:click="colorToFilter = color"
class="color-change-button"
:style="'background-color: ' + color">
<i class="fas fa-filter filter-icon"></i>
</a>
</span>
</div>
<a href="javascript:" v-on:click="createNote()" class="btn btn-sm btn-success">Neue Notiz</a>
</div>
<h5><i class="fa fa-pen"></i> Notizen</h5>
</div>
<template v-for="(note, noteIndex) in $store.state.notes" v-bind:key="noteIndex">
<div v-if="colorToFilter === '' || note.color === colorToFilter" class="col-sm-4 col-md-3 col-lg-2 card-box">
<div class="card">
<div class="card-body note"
:style="'background-color:' + note.color ?? '#ffea77'">
<textarea v-model="note.body" spellcheck="false"
@keydown="this.$store.commit('saveNotes')"></textarea>
<div class="color-changer">
<span v-for="color in noteColors" v-bind:key="color">
<span href="javascript:"
@click="changeColor(note, color);"
class="color-change-button"
v-if="color !== note.color"
:style="'background-color: ' + color">
</span>
</span>
</div>
<div class="float-end">
<a href="javascript:" class="delete-button"
@click="$store.commit('deleteNote', noteIndex)"><i
class="fas fa-trash"></i></a>
</div>
</div>
</div>
</div>
</template>
<span v-if="colorToFilter !== '' && !notesExistInFilteredColor">
Keine Notizen mit gewählter Farbe vorhanden<br>
<a href="javascript:"
class="color-change-button disable-filter-button"
:style="'background-color: '+colorToFilter"
v-on:click="colorToFilter = ''">
Filter ausschalten
</a>
</span>
</div>
</template>
<script>
import axios from "axios";
export default {
name: "Notes",
data() {
return {
noteColors: ['#ffea77', '#ee6352', '#59cd90', '#3fa7d6', '#fac05e', '#f79d84'],
colorToFilter: ''
}
},
methods: {
createNote() {
let component = this;
axios.get(
'https://api.quotable.io/random'
).then((response) => {
component.$store.commit('createNote', response.data.content + '\n - ' + response.data.author);
component.$store.commit('saveNotes');
}).catch(() => {
component.$store.commit('createNote', '');
component.$store.commit('saveNotes');
})
},
changeColor(note, color) {
note.color = color;
this.$store.commit('saveNotes');
}
},
computed: {
notesExistInFilteredColor() {
let component = this;
return this.$store.state.notes.filter((note) => {
return note.color === component.colorToFilter;
}).length;
}
}
}
</script>
<style scoped>
.card-body {
font-family: NotePaper, sans-serif;
}
#note-container {
margin-top: 1em;
}
textarea {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
background-color: transparent;
border: 0 solid transparent;
min-height: 10em;
}
textarea:focus {
outline: none;
}
.color-changer {
position: absolute;
bottom: -0.8em;
z-index: 1000;
}
.color-change-button {
margin-right: 0.2em;
background-color: red;
border-radius: 25px;
padding: 0.2em 0.7em;
text-decoration: none;
}
.color-change-button:hover {
opacity: 0.9;
cursor: pointer;
}
.delete-button {
position: absolute;
bottom: -1.5em;
right: 0.5em;
text-align: right;
background-color: red;
border-radius: 25px;
z-index: 1000;
}
.delete-button i {
margin: 1em;
color: black;
}
.delete-button:hover * {
color: white;
}
.filter-icon {
color: white;
font-size: 0.7em;
}
.disable-filter-button {
color: white;
background-color: grey;
}
.filter-wrapper {
display: inline-block;
margin: 0.3em 1em;
}
.card-box {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
</style>