Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Collected.vue « Popup « Components « vue « src - github.com/marius-wieschollek/passwords-webextension.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fc66bd055c4b60512b9098be22a8b7dfabe9cdac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<template>
    <div class="collected-container">
        <foldout :tabs="tabs" :translate="false" ref="foldout" v-on:switch="switchTab($event)">
            <div class="options" :slot="`${item.getId()}-tab`" v-for="item of items" :key="item.getId()">
                <icon icon="trash-alt" @click="discard(item)"/>
                <icon icon="save" @click="save(item)"/>
            </div>
            <mining-item :item="item" :slot="item.getId()" :key="item.getId()" v-for="item of items"/>
        </foldout>
        <translate tag="div" class="no-results" say="NoCollectedPasswords" v-if="items.length === 0"/>
    </div>
</template>

<script>
    import Icon from '@vue/Components/Icon';
    import Foldout from '@vue/Components/Foldout';
    import Translate from '@vue/Components/Translate';
    import MiningClient from '@js/Queue/Client/MiningClient';
    import MiningItem from '@vue/Components/Collected/MiningItem';
    import MessageService from '@js/Services/MessageService';

    export default {
        components: {MiningItem, Translate, Foldout, Icon},

        props: {
            initialStatus: {
                type   : Object,
                default: () => {
                    return {
                        current: null
                    };
                }
            }
        },

        data() {
            return {
                items  : MiningClient.getItems(),
                current: null
            };
        },

        async mounted() {
            if(this.initialStatus.current !== null && this.tabs.hasOwnProperty(this.initialStatus.current)) {
                this.$refs.foldout.setActive(this.initialStatus.current);
            }
        },

        computed: {
            tabs() {
                let tabs = {};
                for(let item of this.items) {
                    tabs[item.getId()] = item.getLabel();
                }

                return tabs;
            }
        },

        methods: {
            /**
             *
             * @param {MiningItem} item
             * @return {Promise<void>}
             */
            async save(item) {
                await MiningClient.solveItem(item);
                this.items = MiningClient.getItems();
            },

            /**
             *
             * @param {MiningItem} item
             * @return {Promise<void>}
             */
            async discard(item) {
                item.setDiscarded(true);
                await MiningClient.solveItem(item);
                this.items = MiningClient.getItems();
            },

            /**
             *
             * @param {{tab: String}} $event
             */
            switchTab($event) {
                this.current = $event.tab;
            },

            sendStatus() {
                let status = {
                    current: this.current
                };
                MessageService
                    .send({type: 'popup.status.set', payload: {tab: 'collected', status}});
            }
        },

        watch: {
            current() {
                this.sendStatus();
            }
        }
    };
</script>

<style lang="scss">
    .collected-container {
        .no-results {
            line-height : 3rem;
            text-align  : center;
        }
    }
</style>