mirror of
https://github.com/go-shiori/shiori.git
synced 2024-11-11 01:44:02 +08:00
Show error message in web
This commit is contained in:
parent
be95bdf227
commit
dd2c302153
4 changed files with 118 additions and 61 deletions
File diff suppressed because one or more lines are too long
|
@ -24,15 +24,22 @@
|
|||
<i class="fas fa-search fa-fw"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div id="header-menu" v-if="!loading">
|
||||
<a href="#" @click="loadData">
|
||||
<i class="fas fa-sync fa-fw"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="main">
|
||||
<div id="input-bookmark">
|
||||
<template v-if="!loading && error === ''">
|
||||
<div id="input-bookmark" v-if="!loading">
|
||||
<p v-if="inputBookmark.url !== ''">{{inputBookmark.id === -1 ? 'New bookmark' : 'Edit bookmark'}}</p>
|
||||
<input type="text" ref="inputURL" v-model="inputBookmark.url" placeholder="URL for the bookmark">
|
||||
<template v-if="inputBookmark.url !== ''">
|
||||
<input type="text" v-model="inputBookmark.title" placeholder="Custom bookmark title (optional)">
|
||||
<input type="text" v-model="inputBookmark.tags" placeholder="Space separated tags for this bookmark (optional)">
|
||||
<textarea name="excerpt" v-model="inputBookmark.excerpt" placeholder="Excerpt for this bookmark (optional)"></textarea>
|
||||
<p v-if="inputBookmark.error !== ''" class="error-message">{{inputBookmark.error}}</p>
|
||||
<div class="button-area">
|
||||
<div class="spacer"></div>
|
||||
<a v-if="inputBookmark.loading">
|
||||
|
@ -45,7 +52,7 @@
|
|||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div id="grid">
|
||||
<div id="grid" v-if="!loading">
|
||||
<div v-for="column in gridColumns" class="column">
|
||||
<div v-for="item in column" class="bookmark" :ref="'bookmark-'+item.index">
|
||||
<a href="#" class="checkbox">
|
||||
|
@ -74,14 +81,15 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="progress-bar">
|
||||
</template>
|
||||
<div v-if="loading || error !== ''" id="message-bar">
|
||||
<i v-if="loading" class="fas fa-fw fa-spinner fa-spin"></i>
|
||||
<a href="#">Load more bookmarks</a>
|
||||
<p v-if="error !== ''" class="error-message">{{error}}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="dialog.visible" id="dialog-overlay">
|
||||
<div id="dialog">
|
||||
<p id="dialog-title">{{dialog.title}}</p>
|
||||
<p id="dialog-title" :class="{'error-message': dialog.isError}">{{dialog.title}}</p>
|
||||
<p v-html="dialog.content" id="dialog-content"></p>
|
||||
<div id="dialog-button">
|
||||
<div class="spacer"></div>
|
||||
|
@ -98,12 +106,13 @@
|
|||
</div>
|
||||
<script>
|
||||
var instance = axios.create();
|
||||
instance.defaults.timeout = 2500;
|
||||
instance.defaults.timeout = 10000;
|
||||
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
windowWidth: 0,
|
||||
error: "",
|
||||
loading: true,
|
||||
bookmarks: [],
|
||||
inputBookmark: {
|
||||
|
@ -113,11 +122,13 @@
|
|||
title: "",
|
||||
tags: "",
|
||||
excerpt: "",
|
||||
error: "",
|
||||
loading: false
|
||||
},
|
||||
dialog: {
|
||||
visible: false,
|
||||
loading: false,
|
||||
isError: false,
|
||||
title: '',
|
||||
content: '',
|
||||
mainChoice: '',
|
||||
|
@ -128,6 +139,7 @@
|
|||
},
|
||||
methods: {
|
||||
loadData: function () {
|
||||
this.error = '';
|
||||
this.loading = true;
|
||||
instance.get('/api/bookmarks')
|
||||
.then(function (response) {
|
||||
|
@ -135,8 +147,9 @@
|
|||
app.bookmarks = response.data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
var errorMsg = error.response ? error.response.data : error.message;
|
||||
app.loading = false;
|
||||
console.log(error);
|
||||
app.error = errorMsg.trim();
|
||||
});
|
||||
},
|
||||
saveBookmark: function () {
|
||||
|
@ -176,7 +189,9 @@
|
|||
app.clearInputBookmark();
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
var errorMsg = error.response ? error.response.data : error.message;
|
||||
app.inputBookmark.loading = false;
|
||||
app.inputBookmark.error = errorMsg.trim();
|
||||
});
|
||||
},
|
||||
editBookmark: function (idx) {
|
||||
|
@ -202,6 +217,7 @@
|
|||
var bookmark = this.bookmarks[idx];
|
||||
|
||||
this.dialog.visible = true;
|
||||
this.dialog.isError = false;
|
||||
this.dialog.loading = false;
|
||||
this.dialog.title = "Delete Bookmark";
|
||||
this.dialog.content = "Delete <b>\"" + bookmark.title.trim() + "\"</b> from bookmarks ? This action is irreversible.";
|
||||
|
@ -222,9 +238,8 @@
|
|||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
app.dialog.loading = false;
|
||||
app.dialog.visible = false;
|
||||
console.log(error);
|
||||
var errorMsg = error.response ? error.response.data : error.message;
|
||||
app.showDialogError("Error Deleting Bookmark", errorMsg.trim());
|
||||
});
|
||||
};
|
||||
this.dialog.secondAction = function () {
|
||||
|
@ -244,6 +259,7 @@
|
|||
this.inputBookmark.title = "";
|
||||
this.inputBookmark.tags = "";
|
||||
this.inputBookmark.excerpt = "";
|
||||
this.inputBookmark.error = "";
|
||||
this.inputBookmark.loading = false;
|
||||
|
||||
if (idx !== -1) app.$nextTick(function () {
|
||||
|
@ -286,6 +302,19 @@
|
|||
hostname = hostname.split('?')[0];
|
||||
|
||||
return hostname;
|
||||
},
|
||||
showDialogError: function (title, msg) {
|
||||
this.dialog.isError = true;
|
||||
this.dialog.visible = true;
|
||||
this.dialog.loading = false;
|
||||
this.dialog.title = title;
|
||||
this.dialog.content = msg;
|
||||
this.dialog.mainChoice = "OK"
|
||||
this.dialog.secondChoice = ""
|
||||
this.dialog.mainAction = function () {
|
||||
app.dialog.visible = false;
|
||||
}
|
||||
this.dialog.secondAction = function () {}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
|
|
@ -75,6 +75,21 @@
|
|||
padding: 8px 16px;
|
||||
}
|
||||
}
|
||||
#header-menu {
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
a {
|
||||
line-height: @headerHeight;
|
||||
padding: 0 16px;
|
||||
color: @linkColor;
|
||||
font-size: 0.9em;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: @main;
|
||||
background-color: @appBg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#main {
|
||||
margin-top: @headerHeight;
|
||||
|
@ -92,24 +107,29 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
#progress-bar {
|
||||
#message-bar {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
align-items: center;
|
||||
padding: 32px;
|
||||
justify-content: center;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
margin-top: -60px;
|
||||
height: 120px;
|
||||
i {
|
||||
color: @fontLightColor;
|
||||
font-size: 3em;
|
||||
}
|
||||
a {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: @main !important;
|
||||
font-size: 0.9em;
|
||||
&:hover {
|
||||
color: @accent !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.bookmark {
|
||||
|
@ -268,6 +288,13 @@
|
|||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
padding: 16px;
|
||||
&.error-message {
|
||||
color: @main;
|
||||
font-size: 0.9em;
|
||||
border-bottom: 1px solid @border;
|
||||
font-weight: 500;
|
||||
text-transform: none;
|
||||
}
|
||||
}
|
||||
input[type=text],
|
||||
textarea {
|
||||
|
@ -326,6 +353,7 @@
|
|||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
padding: 16px;
|
||||
font-size: 1em;
|
||||
border-bottom: 1px solid @border;
|
||||
}
|
||||
#dialog-content {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
@fontLightColor: #6F757A;
|
||||
@fontSize: 0.9em;
|
||||
@headerHeight: 70px;
|
||||
@main: #3F51B5;
|
||||
@main: #F44336;
|
||||
@accent: #F44336;
|
||||
@headerShadow: rgba(0, 0, 0, 0.3);
|
||||
// Mixin
|
||||
|
|
Loading…
Reference in a new issue