blob: 1ea8d56861164c4e4b4f88a886d67a3a1ceccf52 [file] [log] [blame]
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +02001<script>
Adrià Vilanova Martínez035b5432021-09-03 14:16:59 +02002import {mapGetters} from 'vuex';
3
4import * as ksPb from '../api_proto/kill_switch_pb.js';
5import * as ksObjectsPb from '../api_proto/kill_switch_objects_pb.js';
6
7import EnableKillSwitchDialog from '../components/EnableKillSwitchDialog.vue';
8import KillSwitch from '../components/KillSwitch.vue';
9import MiniMessage from './MiniMessage.vue';
10
11let emptyKillSwitch = new ksObjectsPb.KillSwitch();
12
13export default {
14 data() {
15 return {
16 enableKillSwitchDialog: false,
17 disableDialogOpen: false,
18 currentDisableKillSwitch: emptyKillSwitch.cloneMessage(),
19 killSwitches: [],
20 };
21 },
22 components: {
23 EnableKillSwitchDialog,
24 KillSwitch,
25 MiniMessage,
26 },
27 computed: {
28 ...mapGetters([
29 'isSignedIn',
30 ]),
31 activeKillSwitches() {
32 return this.killSwitches.filter(ks => ks.getActive());
33 },
34 },
35 mounted() {
36 this.loadData();
37 },
38 methods: {
39 loadData() {
40 let request = new ksPb.GetKillSwitchOverviewRequest();
41
42 this.$store.state.client.getKillSwitchOverview(request)
43 .then(res => {
44 this.killSwitches = res.getKillSwitchesList();
45 })
46 .catch(err => console.error(err));
47 },
48 showDisableKillSwitchDialog(killSwitch) {
49 this.currentDisableKillSwitch = killSwitch;
50 this.disableDialogOpen = true;
51 },
52 disableKillSwitch() {
53 let request = new ksPb.DisableKillSwitchRequest();
54 request.setKillSwitchId(this.currentDisableKillSwitch.getId());
55
56 this.$store.state.client.disableKillSwitch(
57 request, {authorization: this.$store.state.jwtToken})
58 .then(res => {
59 this.loadData();
60 this.disableDialogOpen = false;
61 this.currentDisableKillSwitch = emptyKillSwitch.cloneMessage();
62 })
63 .catch(err => console.error(err));
64 },
65 },
66};
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +020067</script>
68
69<template>
Adrià Vilanova Martínez035b5432021-09-03 14:16:59 +020070 <mini-message icon="toggle_off" v-if="activeKillSwitches?.length == 0">
71 There aren't any kill switches enabled currently.<br>
72 Everything's working normally.
73 </mini-message>
74 <template v-else>
75 <div class="kill-switch-container">
76 <kill-switch
77 class="kill-switch"
78 :kill-switch="killSwitch"
79 :can-disable="isSignedIn"
80 @wantsToDisableKillSwitch="showDisableKillSwitchDialog($event)"
81 v-for="killSwitch in activeKillSwitches" />
82 </div>
83 </template>
84
85 <template v-if="isSignedIn">
86 <mcw-fab @click="enableKillSwitchDialog = true" class="enable-kill-switch" icon="add" />
87
88 <mcw-dialog
89 v-model="disableDialogOpen"
90 escape-key-action="close"
91 scrim-click-action="close"
92 aria-labelledby="disable-title"
93 aria-describedby="disable-content"
94 :auto-stack-buttons="true">
95 <mcw-dialog-title id="disable-title">Disable kill switch?</mcw-dialog-title>
96 <mcw-dialog-content id="disable-content">
97 <div>Feature <span class="feature-codename">{{ currentDisableKillSwitch.getFeature()?.getCodename() }}</span> will be progressively enabled to all the users of the extension.</div>
98 </mcw-dialog-content>
99 <mcw-dialog-footer>
100 <mcw-dialog-button action="dismiss">Cancel</mcw-dialog-button>
101 <mcw-dialog-button @click="disableKillSwitch()" action="accept">Confirm</mcw-dialog-button>
102 </mcw-dialog-footer>
103 </mcw-dialog>
104
105 <enable-kill-switch-dialog @kill-switch-added="loadData" v-model="enableKillSwitchDialog" />
106 </template>
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +0200107</template>
Adrià Vilanova Martínez035b5432021-09-03 14:16:59 +0200108
109<style scoped>
110.kill-switch-container {
111 font-family: 'Roboto', 'Helvetica', 'Arial', sans-serif;
112 max-width: 500px;
113 margin: 16px auto;
114}
115
116.kill-switch {
117 margin-bottom: 16px;
118}
119
120.enable-kill-switch {
121 position: fixed;
122 right: 16px;
123 bottom: 16px;
124}
125
126.feature-codename {
127 font-family: 'Roboto Mono', monospace;
128}
129</style>