index.vue 8.23 KB
Newer Older
Esteban Choque's avatar
Esteban Choque committed
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
<template>
  <section
    class="container page">

    <div class="page-header">
      <div
        class="page-img-main"
        :style="{ 'background-image': `url(`+forum.img_dest+`)` }"></div>
      <div class="page-title">
        <h1 v-html=" forum.name "></h1>
        <div class="page-title-details">
          <nuxt-link
            :to="$i18n.path(`participa/`)">
            Participa
          </nuxt-link>
        </div>
      </div>
    </div>

    <div
      class="page-content">
      <p>{{ forum.desc }}</p>
      <el-button 
        type="primary" 
        class="boton_nuevo_debate"
        @click="mostrarDialog">Iniciar Nuevo Debate</el-button>
      <div
        v-for="topic in forum.topics"
        :key="topic.id_forum"
        class="posts">

        <nuxt-link
          :to="$i18n.path(`participa/`+$route.params.id_forum+`/`+$route.params.name_forum+`/`+topic.id_topic+`/`+topic.slug)">
34
35
36
          <h3 
            :style="myStyle" 
            class="categoria">{{ topic.name }}</h3>
Esteban Choque's avatar
Esteban Choque committed
37
38
          <div 
            class="adorno">
39
40
41
42
43
44
            <div
              :style="adorno"  
              class="adorno_izq"></div>
            <div 
              :style="adorno"  
              class="adorno_der"></div>
Esteban Choque's avatar
Esteban Choque committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
          </div>
          <hr class="separador_post">
        </nuxt-link>
        <div
          v-for="pos in topic.posts"
          :key="pos">
          <nuxt-link
            :to="$i18n.path(`participa/`+$route.params.id_forum+`/`+$route.params.name_forum+`/`+topic.id_topic+`/`+topic.slug+`/`+pos.id_post+`/`+pos.slug)">
            {{ pos.title }}
          </nuxt-link>
          <hr class="separador_post">
        </div>
      </div> 
    </div>
    <el-dialog
      title="Iniciar Nuevo Debate"
      :visible.sync="dialogVisible"
62
      width="80%">
Esteban Choque's avatar
Esteban Choque committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
      <table 
        style="width:100%">
        <tr>
          <td>Categoría</td>
        </tr>
        <tr>
          <td>
            <el-select
              v-model="value"
              size="large"
              placeholder="Selecciona un categoría">
              <el-option
                v-for="topic in topics"
                :key="topic.id_topic"
                :label="topic.nombre"
                :value="topic.id_topic">
              </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
84
          <td>Nombre (requerido):</td>
Esteban Choque's avatar
Esteban Choque committed
85
86
87
88
89
90
91
92
93
        </tr>
        <tr>
          <td>
            <el-input 
              placeholder="Escribe tu nombre"
              v-model="nombre"></el-input>
          </td>
        </tr>
        <tr>
94
          <td>Email (no será publicado)(requerido):</td>
Esteban Choque's avatar
Esteban Choque committed
95
96
97
98
99
100
101
102
103
        </tr>
        <tr>
          <td>
            <el-input 
              placeholder="Escribe tu correo"
              v-model="correo"></el-input>
          </td>
        </tr>
        <tr>
104
          <td>Título del debate (Longitud máxima: 80):</td>
Esteban Choque's avatar
Esteban Choque committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        </tr>
        <tr>
          <td>
            <el-input 
              placeholder="Escribe un título para el debate"
              v-model="titulo"></el-input>
          </td>
        </tr>
        <tr>
          <td>Contenido</td>
        </tr>
        <tr>
          <td>
            <el-input
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 8}"
              placeholder="Escribe el contenido para el debate"
              v-model="contenido">
            </el-input>
          </td>
        </tr>
      </table>
Esteban Choque's avatar
Esteban Choque committed
127
128
129
130
131
132
133
134
      <el-row>
        <div id="message">Confirma que eres un humano y no un robot. Por favor resuelve la siguiente operación:</div>
        <p class="question">{{ pregunta }}</p>
        <el-input 
          v-model="respuesta">
        </el-input>
        <p>{{ msg }}</p>		
      </el-row>
Esteban Choque's avatar
Esteban Choque committed
135
136
137
138
139
140
141
      <span 
        slot="footer" 
        class="dialog-footer">
        <el-button 
          @click="dialogVisible = false">Cancelar</el-button>
        <el-button 
          type="primary" 
Esteban Choque's avatar
Esteban Choque committed
142
          @click="verificarRespuesta">Enviar</el-button>
Esteban Choque's avatar
Esteban Choque committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
      </span>
    </el-dialog>


  </section>
</template>

<script>
import axios from 'axios';
export default {
  head () {
    return {
      title: this.forum.name,
    };
  },
  data() {
    return {
      forum: [],
      topics: [],
      dialogVisible: false,
      nombre: '',
      correo: '',
      titulo: '',
      contenido: '',
Esteban Choque's avatar
Esteban Choque committed
167
168
169
170
171
172
      value: '',
      randomNum1: 0,
      randomNum2: 0,
      total: 0,
      pregunta: '',
      respuesta: '',
173
174
175
176
177
178
179
      msg: '',
      myStyle:{
        backgroundColor:''
      },
      adorno:{
        borderTopColor:''
      }
Esteban Choque's avatar
Esteban Choque committed
180
181
182
183
184
185
    };
  },
  mounted () {
    this.$store.commit('CLOSE_MENU');
    this.$util.setBackgroundImage();
    this.getTopics();
Esteban Choque's avatar
Esteban Choque committed
186
    this.crearSuma();
187
188
    this.myStyle.backgroundColor = this.$util.colorpro;
    this.adorno.borderTopColor = this.$util.coloradorno;
Esteban Choque's avatar
Esteban Choque committed
189
190
191
192
193
194
195
  },
  methods: {
    mostrarDialog() {
      this.dialogVisible = true;
      this.getListaCategorias();
    },
    getListaCategorias() {
196
197
      //axios.get('http://localhost/wordpress/index.php?rest_route=/tm/v1/'+this.$route.params.id_forum)
      axios.get(this.$foro.url+'/tm/v1/'+this.$route.params.id_forum)
Esteban Choque's avatar
Esteban Choque committed
198
199
200
201
202
203
      .then(response => {
        this.topics = response.data;
        console.log(response.status); // ex.: 200
     }); 
    },
    getTopics() {
204
205
     //axios.get('http://localhost/wordpress/index.php?rest_route=/forum_topic_posts_5/v1/'+this.$route.params.id_forum)
     axios.get(this.$foro.url+'/forum_topic_posts_5/v1/'+this.$route.params.id_forum)
Esteban Choque's avatar
Esteban Choque committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
      .then(response => {
        this.forum = response.data[this.$route.params.id_forum];
        console.log(response.status); // ex.: 200
     }); 
    },
    sendPublicacion() {
      this.params = {
        id_topic: this.value,
        nombre: this.nombre,
        correo: this.correo,
        post_title: this.titulo,
        the_content: this.contenido
      };
      this.dialogVisible = false;
220
221
      //axios.post('http://localhost/wordpress/index.php?rest_route=/addPublicacion/v1/', this.params)
      axios.post(this.$foro.url+'/addPublicacion/v1/', this.params)
Esteban Choque's avatar
Esteban Choque committed
222
223
224
225
226
227
228
      .then(response => {
        this.getTopics();
        this.nombre = "";
        this.correo = "";
        this.titulo = "";
        this.contenido = "";
     });
Esteban Choque's avatar
Esteban Choque committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
    },
    getRandom() {
      return Math.ceil(Math.random()* 20);
    },
    crearSuma() {
      this.randomNum1 = this.getRandom(),
      this.randomNum2 = this.getRandom();
      this.total = this.randomNum1 + this.randomNum2;
      this.pregunta = this.randomNum1 + ' + ' + this.randomNum2 + ' = ?' ;
      this.respuesta = '';
    },
    verificarRespuesta() {
      if(this.respuesta == this.total)
      {
        this.msg = 'Respuesta correcta';
        this.randomNum1 = 0;
        this.randomNum2 = 0;
        this.total = 0;
        this.pregunta = '';
        this.respuesta = '';
        this.sendPublicacion();
        this.crearSuma();
      }
      else
      {
        this.msg = 'Respuesta incorrecta, intenta de nuevo por favor';
        this.crearSuma();
      }
Esteban Choque's avatar
Esteban Choque committed
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
    }
  }
};
</script>


<style lang="scss" src="./page.scss"></style>
<style lang="scss">
.separador_topic
{
  display: block !important;
  margin-top: 0.5em !important;
  margin-bottom: 0.5em !important;
  margin-left: auto !important;
  margin-right: auto !important;
  border-style: inset !important;
  border-width: 1px !important;
}
.separador_post
{
  display: block !important;
  margin-top: 0.5em !important;
  margin-bottom: 0.5em !important;
  margin-left: auto !important;
  margin-right: auto !important;
  border-style: inset !important;
  border-width: 1px !important;
  border-top: 1px solid #e8e8e8 !important;
}
.nombre_topic
{
  font-weight: bold !important;
}
.posts
{
  margin-bottom:10px;
}
.categoria
{
  background: #024f9b;
  color:#fff;
  text-align: left;
  font-weight: bold;
  margin-left: -35px;
  margin-right: -35px;
  padding-top: 15px;
  padding-right: 25px;
  padding-bottom: 15px;
  padding-left: 25px;
}
.adorno
{
  position: relative;
  top: -21px;
  margin-left: -35px;
  margin-right: -25px;
}
.adorno_izq
{
  position: absolute;
  top: 0px;
  left: -2x;
  width: 0;
  height: 0;
  border-top: 10px solid #012d59;
  border-left: 10px solid transparent;
}
.adorno_der
{
  position: absolute;
  top: 0px;
  left: 100%;
  width: 0; 
  height: 0; 
  border-top: 10px solid #012d59; 
  border-right: 10px solid transparent;
}
Esteban Choque's avatar
Esteban Choque committed
334
335
336
337
.question
{
  font-size: 1.5em;
}
Esteban Choque's avatar
Esteban Choque committed
338
</style>