Преглед изворни кода

implement message system

pull/342/head
Guillaume Vincent пре 7 година
родитељ
комит
9670604875
8 измењених фајлова са 95 додато и 4 уклоњено
  1. +5
    -1
      src/LessPass.vue
  2. +42
    -0
      src/components/Message.vue
  3. +13
    -1
      src/store/actions.js
  4. +1
    -1
      src/store/getters.js
  5. +2
    -0
      src/store/mutation-types.js
  6. +7
    -1
      src/store/mutations.js
  7. +9
    -0
      test/store.getters.js
  8. +16
    -0
      test/store.mutations.js

+ 5
- 1
src/LessPass.vue Прегледај датотеку

@@ -2,6 +2,7 @@
<div id="lesspass" class="card" style="max-width: 420px;"
v-bind:class="{ 'v1': version===1, 'v2': version===2 }">
<lesspass-menu></lesspass-menu>
<lesspass-message></lesspass-message>
<div class="card-block">
<router-view></router-view>
</div>
@@ -10,15 +11,18 @@
<script type="text/ecmascript-6">
import './LessPass.scss';
import Menu from './components/Menu.vue';
import Message from './components/Message.vue';
import {mapGetters} from 'vuex';

export default {
name: 'LessPass',
components: {
'lesspass-menu': Menu
'lesspass-menu': Menu,
'lesspass-message': Message
},
computed: mapGetters(['version']),
created(){
this.$store.dispatch('cleanMessage');
this.$store.dispatch('loadPasswordFirstTime');
this.$store.dispatch('refreshToken');
}


+ 42
- 0
src/components/Message.vue Прегледај датотеку

@@ -0,0 +1,42 @@
<style>
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}

.fade-enter, .fade-leave-to {
opacity: 0
}

#message {
position: absolute;
top: 49px;
left: 0;
right: 0;
z-index: 20;
}
</style>
<template>
<div id="message">
<transition name="fade">
<div v-if="message.text">
<div class="card-header text-white"
v-bind:class="{ 'card-warning': message.status==='warning', 'card-danger': message.status==='error', 'card-success': message.status==='success' }">
<div class="row">
<div class="col-12">
<small>message</small>
</div>
</div>
</div>
</div>
</transition>
</div>
</template>
<script type="text/ecmascript-6">
import {mapGetters} from 'vuex';

export default {
computed: mapGetters([
'message'
])
}
</script>

+ 13
- 1
src/store/actions.js Прегледај датотеку

@@ -82,4 +82,16 @@ export const deletePassword = ({commit, state}, payload) => {
.then(() => {
commit(types.DELETE_PASSWORD, payload);
});
};
};

export const displayMessage = ({commit}, payload) => {
commit(types.SET_MESSAGE, {message: payload});
setTimeout(() => {
commit(types.CLEAN_MESSAGE);
}, 3000);
};


export const cleanMessage = ({commit}, payload) => {
commit(types.CLEAN_MESSAGE);
};

+ 1
- 1
src/store/getters.js Прегледај датотеку

@@ -10,7 +10,7 @@ export const isGuest = state => !state.authenticated;

export const baseURL = state => state.baseURL;

export const passwordStatus = state => state.passwordStatus;
export const message = state => state.message;

export const version = state => {
if (state.password === null || state.route.path === '/options/default') {


+ 2
- 0
src/store/mutation-types.js Прегледај датотеку

@@ -10,3 +10,5 @@ export const SET_BASE_URL = 'SET_BASE_URL';
export const SET_VERSION = 'SET_VERSION';
export const LOAD_PASSWORD_FIRST_TIME = 'LOAD_PASSWORD_FIRST_TIME';
export const LOAD_PASSWORD_FOR_SITE = 'LOAD_PASSWORD_FOR_SITE';
export const SET_MESSAGE = 'SET_MESSAGE';
export const CLEAN_MESSAGE = 'CLEAN_MESSAGE';

+ 7
- 1
src/store/mutations.js Прегледај датотеку

@@ -60,5 +60,11 @@ export default {
break;
}
}
}
},
[types.SET_MESSAGE](state, {message}){
state.message = message;
},
[types.CLEAN_MESSAGE](state){
state.message = {text: '', status: 'success'};
},
};

+ 9
- 0
test/store.getters.js Прегледај датотеку

@@ -48,4 +48,13 @@ test('passwordURL', t => {
};

t.is(getters.passwordURL(state), 'https://lesspass.com/#/?login=test@example.org&site=example.org&uppercase=true&lowercase=true&numbers=true&symbols=false&length=16&counter=1&version=2')
});

test('message', t => {
const state = {
message: {text: 'error message', status:'error'}
};
const message = getters.message(state);
t.is(message.text, state.message.text);
t.is(message.status, state.message.status);
});

+ 16
- 0
test/store.mutations.js Прегледај датотеку

@@ -278,4 +278,20 @@ test('LOAD_PASSWORD_FOR_SITE multiple accounts matching criteria', t => {
LOAD_PASSWORD_FOR_SITE(state, {site: 'www.google.com', url: 'https://www.google.com'});
t.is(state.password.id, '2');
t.is(state.password.site, 'www.google.com');
});

test('SET_MESSAGE', t => {
const SET_MESSAGE = mutations[types.SET_MESSAGE];
const state = {};
SET_MESSAGE(state, {message: {text: 'success message', status: 'success'}});
t.is(state.message.text, 'success message');
t.is(state.message.status, 'success');
});

test('CLEAN_MESSAGE', t => {
const CLEAN_MESSAGE = mutations[types.CLEAN_MESSAGE];
const state = {message: {text: 'error message', status: 'error'}};
CLEAN_MESSAGE(state);
t.is(state.message.text, '');
t.is(state.message.status, 'success');
});

Loading…
Откажи
Сачувај