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

FeedbackQuestion.vue « FeedbackQuestion « src « vue « Feedback « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 52fa9cd9fa96d8a8058485cfa674b40ef9a6f9dc (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!--
  Matomo - free/libre analytics platform
  @link https://matomo.org
  @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
-->

<template>
  <div>
    <div v-if="!isHidden" class="bannerHeader">
      <span>{{ translate(`Feedback_FeedbackTitle`) }} <i class="icon-heart red-text"></i></span>
      <a @click="showQuestion" class="btn">
        {{ translate(`Feedback_Question${question}`) }}
      </a>
      <a class="close-btn" @click="disableReminder">
        <i class="icon-close white-text"></i></a>
    </div>
    <div class="ratefeature">
      <MatomoDialog
        v-model="showFeedbackForm"
        @validation="sendFeedback()"
      >
        <div
          class="ui-confirm ratefeatureDialog"
        >
          <h2>{{ translate(`Feedback_Question${question}`) }}</h2>
          <p
            v-html="translate('Feedback_FeedbackSubtitle',
            `<i class='icon-heart red-text'></i>`)"></p>
          <br/>
          <div class="messageContainer">
            <div class="error-text" v-if="errorMessage">{{ errorMessage }}</div>
            <textarea id="message" :class="{'has-error':errorMessage}" v-model="feedbackMessage"/>
          </div>
          <br/>
          <p
            v-html="translate('Feedback_Policy',`<a rel='nofollow' href='https://matomo.org/privacy-policy/' target='_blank'>`,'</a>')"></p>
          <input
            type="button"
            role="validation"
            :value="translate('Feedback_SendFeedback')"
          />
          <input
            type="button"
            role="cancel"
            :value="translate('General_Cancel')"
          />
        </div>
      </MatomoDialog>
      <MatomoDialog v-model="feedbackDone">
        <div
          class="ui-confirm ratefeatureDialog"
        >
          <h2>{{ translate(`Feedback_ThankYou`) }}</h2>
          <p v-html="translate('Feedback_ThankYourForFeedback',
        `<i class='icon-heart red-text'></i>`)">
          </p>
          <input
            type="button"
            role="cancel"
            :value="translate('General_Close')"
          />
        </div>
      </MatomoDialog>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import {
  MatomoDialog, AjaxHelper, setCookie, getCookie, translate,
} from 'CoreHome';

const { $ } = window;

const cookieName = 'feedback-question';
export default defineComponent({

  props: {
    showQuestionBanner: String,
  },
  components: {
    MatomoDialog,
  },
  computed: {
    isHidden() {
      if (this.showQuestionBanner === '0') {
        return true;
      }
      return !!this.hide;
    },
  },
  data() {
    return {
      questionText: '',
      question: 0,
      hide: null,
      feedbackDone: false,
      expanded: false,
      showFeedbackForm: false,
      feedbackMessage: null,
      errorMessage: null,
    };
  },
  watch: {
    showFeedbackForm(val) {
      // eslint-disable-next-line no-underscore-dangle
      this.questionText = translate(`Feedback_Question${this.question}`);
      if (val) {
        setInterval(() => {
          $('#message').focus();
        }, 500);
      }
    },
  },
  created() {
    if (this.showQuestionBanner !== '0') {
      this.initQuestion();
    }
  },
  methods: {
    initQuestion() {
      if (!getCookie(cookieName)) {
        this.question = this.getRandomIntBetween(0, 4);
      } else {
        // eslint-disable-next-line radix
        this.question = parseInt(getCookie(cookieName));
      }

      const nextQuestion = (this.question + 1) % 4;
      const sevenDays = 7 * 60 * 60 * 24 * 1000;
      setCookie(cookieName, nextQuestion, sevenDays);
    },
    getRandomIntBetween(min, max) {
      // eslint-disable-next-line no-param-reassign
      min = Math.ceil(min);
      // eslint-disable-next-line no-param-reassign
      max = Math.floor(max);
      return Math.floor(Math.random() * (max - min + 1) + min);
    },
    showQuestion() {
      this.showFeedbackForm = true;
      this.errorMessage = null;
    },
    disableReminder() {
      AjaxHelper.fetch({
        method: 'Feedback.updateFeedbackReminderDate',
      });
      this.hide = true;
    },
    async sendFeedback() {
      this.errorMessage = null;
      const res = await AjaxHelper.fetch({
        method: 'Feedback.sendFeedbackForSurvey',
        question: this.questionText,
        message: this.feedbackMessage,
      });

      if (res.value === 'success') {
        $('.modal').modal('close');
        this.feedbackDone = true;
        this.hide = true;
      } else {
        this.errorMessage = res.value;
      }
    },
  },
});
</script>