Browse Source

Add notes;

master
stingl 5 years ago
parent
commit
b1536269a8
  1. 14
      .idea/workspace.xml
  2. 77
      app.js
  3. 36
      index.html

14
.idea/workspace.xml

@ -6,7 +6,8 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e3f098f0-e98c-435a-af04-d153c9525633" name="Default Changelist" comment=""> <list default="true" id="e3f098f0-e98c-435a-af04-d153c9525633" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.css" beforeDir="false" afterPath="$PROJECT_DIR$/app.css" afterDir="false" /> <change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/index.html" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -19,7 +20,9 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="PhpDebugGeneral" listening_started="true" /> <component name="GitToolBoxStore">
<option name="projectConfigVersion" value="2" />
</component>
<component name="ProjectId" id="1g0vdLKoCZC7Ep9S79Z434EvL8a" /> <component name="ProjectId" id="1g0vdLKoCZC7Ep9S79Z434EvL8a" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState"> <component name="ProjectViewState">
@ -32,6 +35,7 @@
<property name="last.edited.regexp" value="Why, ever, would you? Stupid! pf." /> <property name="last.edited.regexp" value="Why, ever, would you? Stupid! pf." />
<property name="nodejs_package_manager_path" value="npm" /> <property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.keymap" /> <property name="settings.editor.selected.configurable" value="preferences.keymap" />
<property name="vue.rearranger.settings.migration" value="true" />
</component> </component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
@ -48,6 +52,7 @@
<workItem from="1597530844649" duration="131000" /> <workItem from="1597530844649" duration="131000" />
<workItem from="1597577497243" duration="3353000" /> <workItem from="1597577497243" duration="3353000" />
<workItem from="1597583294362" duration="11703000" /> <workItem from="1597583294362" duration="11703000" />
<workItem from="1600432025720" duration="2181000" />
</task> </task>
<task id="LOCAL-00001" summary="Adds gitignore."> <task id="LOCAL-00001" summary="Adds gitignore.">
<created>1597348071361</created> <created>1597348071361</created>
@ -381,10 +386,11 @@
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="0" y="0" width="616" height="720" key="find.popup/0.0.1366.720@0.0.1366.720" timestamp="1597346688624" /> <state x="0" y="0" width="616" height="720" key="find.popup/0.0.1366.720@0.0.1366.720" timestamp="1597346688624" />
<state width="486" height="302" key="javadoc.popup.new" timestamp="1597589385567"> <state width="684" height="487" key="javadoc.popup.new" timestamp="1600433639818">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1920" height="1160" />
</state> </state>
<state width="486" height="302" key="javadoc.popup.new/0.0.1366.720@0.0.1366.720" timestamp="1597589385567" /> <state width="486" height="302" key="javadoc.popup.new/0.0.1366.720@0.0.1366.720" timestamp="1597589385567" />
<state width="684" height="487" key="javadoc.popup.new/0.0.1920.1160/-1920.0.1920.1040@0.0.1920.1160" timestamp="1600433639818" />
<state x="347" y="155" key="run.anything.popup" timestamp="1597587322870"> <state x="347" y="155" key="run.anything.popup" timestamp="1597587322870">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>

77
app.js

@ -6,6 +6,7 @@ let kara = new Vue({
chatbox: null, chatbox: null,
isTyping: false, isTyping: false,
askedForName: false, askedForName: false,
takeNote: false,
username: '', username: '',
themes: null, themes: null,
activeTheme: 'slate', activeTheme: 'slate',
@ -20,6 +21,7 @@ let kara = new Vue({
name: null, name: null,
username: null username: null
}, },
notes: [],
answers: [ answers: [
{ {
includeAll: false, includeAll: false,
@ -121,8 +123,16 @@ let kara = new Vue({
this.isTyping = true; this.isTyping = true;
setTimeout(() => { setTimeout(() => {
if (this.askedForName === true) { // Check commands
if (this.checkForCommands(message, 'note')) {
let noteToSave = this.checkForCommands(message, 'note');
this.saveNote(noteToSave);
} else if (this.checkForCommands(message, 'clear')) {
this.clearChat();
} else if (this.askedForName === true) {
this.setName(message) this.setName(message)
} else if (this.takeNote === true) {
this.saveNote(message)
} else { } else {
let answer = this.getAnswer(message); let answer = this.getAnswer(message);
if (answer) { if (answer) {
@ -134,7 +144,7 @@ let kara = new Vue({
this.isTyping = false; this.isTyping = false;
this.scrollDown(); this.scrollDown();
}, 3000); }, 2000);
}, },
scrollDown() { scrollDown() {
$('#chat-box').stop().animate({ $('#chat-box').stop().animate({
@ -144,9 +154,7 @@ let kara = new Vue({
oneOf(answers) { oneOf(answers) {
let amountOfAnswers = answers.length; let amountOfAnswers = answers.length;
let randomIndex = Math.floor(Math.random() * (amountOfAnswers)); let randomIndex = Math.floor(Math.random() * (amountOfAnswers));
console.log(randomIndex);
console.log(answers[randomIndex]);
return this.convertWildcards(answers[randomIndex]); return this.convertWildcards(answers[randomIndex]);
}, },
convertWildcards(message) { convertWildcards(message) {
@ -177,6 +185,28 @@ let kara = new Vue({
return includesAllPhrases; return includesAllPhrases;
}, },
checkForCommands(message, commands) {
if (!Array.isArray(commands)) {
commands = [commands];
}
let commandFound = false;
let parameter = false;
commands.forEach((command) => {
if (commandFound) {
return;
}
let commandString = '/' + command;
if (message.search(commandString) === 0) {
parameter = message.replace(commandString, '').trim();
commandFound = true;
}
});
return parameter ? parameter : commandFound;
},
cleanupMessage(message) { cleanupMessage(message) {
message = message.toLowerCase(); message = message.toLowerCase();
return message.replace('?', '') return message.replace('?', '')
@ -205,6 +235,7 @@ let kara = new Vue({
}, },
getAnswer(message) { getAnswer(message) {
message = this.cleanupMessage(message); message = this.cleanupMessage(message);
let phrases = message.split(' '); let phrases = message.split(' ');
let answer = undefined; let answer = undefined;
@ -213,6 +244,19 @@ let kara = new Vue({
return "Please tell me how i should call you."; return "Please tell me how i should call you.";
} }
if (
this.includesAllOf(phrases, ['new', 'note']) ||
this.includesAllOf(phrases, ['new', 'task']) ||
this.includesAllOf(phrases, ['save', 'to', 'clipboard'])
) {
this.takeNote = true;
return this.oneOf([
"What do you wan't me to save for you?",
"Tell me what you wan't to save.",
"What is it you wan't to save?",
]);
}
if (this.includesAllOf(phrases, ['clear', 'chat'])) { if (this.includesAllOf(phrases, ['clear', 'chat'])) {
this.clearChat() this.clearChat()
return false; return false;
@ -267,7 +311,6 @@ let kara = new Vue({
let includeAll = this.addModal.includeAll; let includeAll = this.addModal.includeAll;
let keywords = this.cleanupMessage(this.addModal.keywords).split(','); let keywords = this.cleanupMessage(this.addModal.keywords).split(',');
let responses = this.addModal.responses; let responses = this.addModal.responses;
console.log(this.addModal.responses);
this.answers.push({ this.answers.push({
includeAll: includeAll, includeAll: includeAll,
@ -287,6 +330,7 @@ let kara = new Vue({
localStorage.setItem('activeTheme', this.activeTheme); localStorage.setItem('activeTheme', this.activeTheme);
localStorage.setItem('messages', JSON.stringify(this.messages)); localStorage.setItem('messages', JSON.stringify(this.messages));
localStorage.setItem('answers', JSON.stringify(this.answers)); localStorage.setItem('answers', JSON.stringify(this.answers));
localStorage.setItem('notes', JSON.stringify(this.notes));
}, },
getSavedData() { getSavedData() {
let savedName = localStorage.getItem('name'); let savedName = localStorage.getItem('name');
@ -305,6 +349,9 @@ let kara = new Vue({
let savedAnswers = JSON.parse(localStorage.getItem('answers')); let savedAnswers = JSON.parse(localStorage.getItem('answers'));
this.answers = savedAnswers ? savedAnswers : this.answers; this.answers = savedAnswers ? savedAnswers : this.answers;
let savedNotes = JSON.parse(localStorage.getItem('notes'));
this.notes = savedNotes ? savedNotes : this.notes;
this.scrollDown(); this.scrollDown();
}, },
askForName() { askForName() {
@ -333,6 +380,24 @@ let kara = new Vue({
]) ])
) )
}, },
saveNote(message) {
this.takeNote = false;
this.notes.push({
time: moment(),
body: message,
checked: false
});
this.updateStorage();
this.botMessage(
this.oneOf([
"Saved! :)",
"You can read and check your notes in the clipboard-section. :)"
])
)
},
saveSettings() { saveSettings() {
this.name = this.settingsModal.name; this.name = this.settingsModal.name;
this.username = this.settingsModal.username; this.username = this.settingsModal.username;
@ -344,6 +409,7 @@ let kara = new Vue({
clearChat() { clearChat() {
this.messages = []; this.messages = [];
this.botMessage('Chat cleared.'); this.botMessage('Chat cleared.');
this.updateStorage();
}, },
clearStorage() { clearStorage() {
localStorage.clear(); localStorage.clear();
@ -354,7 +420,6 @@ let kara = new Vue({
axios.get('https://bootswatch.com/api/4.json') axios.get('https://bootswatch.com/api/4.json')
.then(function (response) { .then(function (response) {
console.log(response.data.themes);
vue.themes = response.data.themes; vue.themes = response.data.themes;
}) })
.catch(function (error) { .catch(function (error) {

36
index.html

@ -17,6 +17,9 @@
<div class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#addModal"> <div class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#addModal">
<i class="fas fa-plus"></i> <i class="fas fa-plus"></i>
</div> </div>
<div class="btn btn-sm btn-secondary" data-toggle="modal" data-target="#noteModal" v-if="notes.length > 0">
<i class="fas fa-clipboard"></i>
</div>
<div class="btn btn-sm btn-secondary" @click="scrollDown()"> <div class="btn btn-sm btn-secondary" @click="scrollDown()">
<i class="fas fa-chevron-down"></i> <i class="fas fa-chevron-down"></i>
</div> </div>
@ -98,6 +101,39 @@
</div> </div>
</div> </div>
<div class="modal fade" id="noteModal" tabindex="-1" role="dialog" aria-labelledby="noteModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Notes</h5>
</div>
<div class="modal-body" style="max-height: 800px; overflow-y: scroll">
<ul class="list-group">
<li class="list-group-item" v-for="note in notes" v-if="!note.checked">
<span class="float-right">
<input type="checkbox" v-model="note.checked" @change="updateStorage()"/>
</span>
{{ note.body }}
</li>
</ul>
<hr/>
<ul class="list-group">
<li class="list-group-item" v-for="note in notes" v-if="note.checked">
<span class="float-right">
<input type="checkbox" v-model="note.checked" @change="updateStorage()"/>
</span>
<span style="text-decoration: line-through;">{{ note.body }}</span>
</li>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="settingsModal" tabindex="-1" role="dialog" aria-labelledby="settingsModal" aria-hidden="true"> <div class="modal fade" id="settingsModal" tabindex="-1" role="dialog" aria-labelledby="settingsModal" aria-hidden="true">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">

Loading…
Cancel
Save