Skip to content

Commit

Permalink
rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
tridays committed Nov 13, 2016
1 parent f109818 commit 585469e
Show file tree
Hide file tree
Showing 19 changed files with 1,736 additions and 1,251 deletions.
16 changes: 11 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ module.exports = {
// allow func()
'space-before-function-paren': 0,
// allow blank line before }
'padded-blocks': 1,
'padded-blocks': 0,
// allow semicolon
'semi': 0,
// allow unused defined var
'no-unused-vars': 1,
'no-unused-vars': 0,
// allow indent
'indent': 1,
'indent': 0,
// allow quotes
'quotes': 1,
'quotes': 0,
// allow same line properties
'object-property-newline': 1,
'object-property-newline': 0,

'operator-linebreak': 0,

'keyword-spacing': 0,

'no-trailing-spaces': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Library Management System</title>
<title>Purjoy Library Management System</title>
<link href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet">
</head>
Expand Down
98 changes: 41 additions & 57 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,86 @@

<router-link id="header-title" to="/">Purjoy Library Management System</router-link>

<div class="user-operation-panel" v-if="login">
<span>Welcome <router-link id="username" to="/my">{{account.name}} </router-link></span>
<div v-if="isLogin" class="user-operation-panel" >
<span>Welcome, <router-link id="username" to="/user">{{account.name}}</router-link></span>

<div v-if="isAdmin" class="action-bar">
<h5 class="admin"> ( admin ) </h5>

<span class="button-divider">|</span>
<router-link to="/loan_management" class="header-button">Manage loans</router-link>
<router-link to="/admin/books" class="header-button">Manage Books</router-link>

<span class="button-divider">|</span>
<router-link to="/book_management" class="header-button">Manage Books</router-link>
<router-link to="/admin/borrows" class="header-button">Manage Borrows</router-link>

<span class="button-divider">|</span>
<router-link to="/user_management" class="header-button">Manage Users</router-link>
</div>
<div class="action-bar" v-else>
<div class="button-divider">|</div>
<router-link to="/my/borrow_records" class="header-button">My Borrow Record</router-link>
<router-link to="/admin/users" class="header-button">Manage Users</router-link>
</div>

<span class="action-bar" v-else>
<span class="button-divider">|</span>
<router-link to="/my/borrow_records" class="header-button">My Borrow Records</router-link>
<router-link to="/user/borrows" class="header-button">My Borrows</router-link>
</span>

<div class="button-divider">|</div>
<a class="header-button" @click="logout">Logout</a>
<a href="#" class="header-button" @click="logout">Logout</a>
</div>
<div class="user-operation-panel" v-if="!login">
<router-link to="/login" class="header-button">Login</router-link>

<div class="user-operation-panel" v-else>
<router-link to="/user/login" class="header-button">Login</router-link>
<div class="button-divider">|</div>
<router-link to="/register" class="header-button">Register</router-link>
<router-link to="/user/register" class="header-button">Register</router-link>
</div>

</div>

<transition name="fade" mode="out-in">
<router-view class="view"></router-view>
</transition>

<div class="container clearfix">
<hr/>
<footer class="text-muted">
SPM 2016.
</footer>
<br/>
</div>
</div>
</template>

<script>
import Hello from './components/Hello'
import Home from './views/Home';
export default {
components: {
Hello
Home
},
data() {
return {
// login: this.$store.state.isLogin,
// user: this.$store.state.user
}
},
methods: {
logout() {
this.$store.dispatch('LOGOUT')
this.$router.push('/index')
this.$store.dispatch('LOGOUT');
this.$router.push('/index');
}
},
computed: {
login() {
isLogin() {
return this.$store.getters.isLogin;
},
account() {
return this.$store.state.account;
return this.$store.getters.getAccount;
},
isAdmin() {
return this.$store.state.account.roles.indexOf('ADMIN') !== -1
return this.$store.getters.isAdmin;
}
}
}
};
</script>

<style>
html {
height: 100%;
}
Expand All @@ -94,8 +97,8 @@
#app {
color: #2c3e50;
font-family: Source Sans Pro, Helvetica, sans-serif;
text-align: center;
/*font-family: Source Sans Pro, Helvetica, sans-serif;*/
/*text-align: center;*/
width: 100%;
}
Expand All @@ -111,11 +114,6 @@
font-style: normal;
}
.header-button {
font-size: 0.9em;
color: #42b983;
}
#header {
padding: 10px 20px 10px 20px;
display: flex;
Expand All @@ -142,39 +140,25 @@
}
.button-divider {
margin-left: 10px;
margin-right: 10px;
margin-left: 5px;
margin-right: 5px;
color: #cccccc;
}
.action-button {
padding: 8px 16px 8px 16px;
background: #42b983;
color: #ffffff;
border-width: 0;
border-radius: 4px;
#user-operation-panel #admin {
margin-left: 10px;
padding-right: 4px;
}
input {
border: 1px solid #eeeeee;
padding: 8px;
margin: 8px 16px 8px 16px;
.fade-enter-active, .fade-leave-active {
transition: opacity .3s
}
textarea {
border: 1px solid #eeeeee;
padding: 8px;
margin: 8px 16px 8px 16px;
.fade-enter, .fade-leave-active {
opacity: 0
}
#username {
text-decoration: underline;
* {
border-radius: 0 !important;
}
#user-operation-panel #admin {
margin-left: 10px;
padding-right: 4px;
}
</style>
112 changes: 112 additions & 0 deletions src/components/BookTraceList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<template>
<div class="trace-list">
<div v-if="traces && traces.length">
<table class="table table-bordered table-condensed table-hover">
<thead>
<tr>
<th>trace</th>
<th>status</th>
<th>operation</th>
</tr>
</thead>
<tbody>
<tr v-for="trace in traces" v-show="isTraceVisible(trace)">
<td>No.{{ trace.id }} on "{{ trace.location }}"</td>
<td>{{ trace.status }}</td>
<td>
<template v-if="isLogin">
<button v-show="isTraceBorrowable(trace)" @click="borrow(trace)" class="">
borrow
</button>
<template v-if="trace.status === 'BORROWED'">
<button @click="reserve(trace)" v-show="isTraceReservable(trace)">
reserve
</button>
</template>
</template>
<template v-else>
Please login first.
</template>
</td>
</tr>
</tbody>
</table>
</div>
<template v-else>
no book trace yet.
</template>
</div>
</template>

<script>
import * as service from '../service';
let inArray = (arr, element) => {
if (arr instanceof Array) {
for (let i in arr) {
let e = arr[i];
if (e === element) {
return true;
}
}
return false;
}
return undefined;
};
export default {
props: [
'traces'
],
watch: {},
computed: {
isLogin() {
return this.$store.getters.isLogin;
},
isReachLimit() {
return this.$store.getters.getAccount.loanLimit === 0;
},
DUMP() {
}
},
methods: {
isTraceVisible: function(e) {
return e && inArray(['NORMAL', 'LOCKED', 'BORROWED'], e.status);
},
isTraceBorrowable: function(trace) {
return trace.status === 'NORMAL';
},
isTraceReservable: function(trace) {
return !!trace.isReservable && this.$store.account.id !== trace.loan.userId;
},
borrow: function(trace) {
service.borrowBookTrace(trace).then(response => {
if (response.data.success) {
trace.status = 'LOCKED';
alert('book trace is locked successfully, please ask the administrator to check in 2 hours.');
} else {
alert(response.data.error);
}
}).catch(e => {
alert(e);
});
},
reserve: function(trace) {
service.reserveBookTrace(trace).then(response => {
if (response.data.success) {
trace.isReservable = false;
alert('book trace is reserved successfully, you\'ll receive our notice mail after it is returned.');
} else {
alert(response.data.error);
}
}).catch(e => {
alert(e);
});
}
}
}
</script>
32 changes: 17 additions & 15 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Vue from 'vue'
import Router from 'vue-router'
import Vue from 'vue';
import Router from 'vue-router';

import LoginView from '../views/Login.vue'
import HomeView from '../views/Home.vue'
import RegisterView from '../views/Register.vue'
import UserView from '../views/User.vue'
import BorrowRecordsView from '../views/BorrowRecords.vue'
import BookManagementView from '../views/admin/BookManagement.vue'
import LoanManagementView from '../views/admin/LoanManagement.vue'
import HomeView from '../views/Home';
import LoginView from '../views/Login';
import RegisterView from '../views/Register';
import UserView from '../views/User';
import BorrowRecordsView from '../views/Borrows';
import BookManagementView from '../views/admin/BookManagement';
import BorrowManagementView from '../views/admin/BorrowManagement';
import UserManagementView from '../views/admin/UserManagement';

Vue.use(Router);

Expand All @@ -16,12 +17,13 @@ var router = new Router({
scrollBehavior: () => ({y: 0}),
routes: [
{ path: '/index', component: HomeView },
{ path: '/login', component: LoginView },
{ path: '/register', component: RegisterView },
{ path: '/my', component: UserView },
{ path: '/my/borrow_records', component: BorrowRecordsView },
{ path: '/book_management', component: BookManagementView },
{ path: '/loan_management', component: LoanManagementView },
{ path: '/user/login', component: LoginView },
{ path: '/user/register', component: RegisterView },
{ path: '/user', component: UserView },
{ path: '/user/borrows', component: BorrowRecordsView },
{ path: '/admin/books', component: BookManagementView },
{ path: '/admin/borrows', component: BorrowManagementView },
{ path: '/admin/users', component: UserManagementView },
{ path: '*', redirect: '/index' }
]
});
Expand Down
Loading

0 comments on commit 585469e

Please sign in to comment.