|
1 |
| -const Vue = require('vue/dist/vue.js') |
2 |
| -const marked = require('marked') |
| 1 | +<template> |
| 2 | + <div class="add-form form-horizontal"> |
3 | 3 |
|
4 |
| -Vue.component('add-form', { |
5 |
| - props: ['problemProp', 'solutionProp', 'keywordStringProp'], |
6 |
| - data: function() { |
7 |
| - return { |
8 |
| - problem: this.problemProp || '', |
9 |
| - solution: this.solutionProp || '', |
10 |
| - keywordString: this.keywordStringProp || '' |
11 |
| - } |
12 |
| - }, |
13 |
| - computed: { |
14 |
| - keywords: { |
15 |
| - get: function() { |
16 |
| - let result |
17 |
| - |
18 |
| - // Split into keywords |
19 |
| - result = this.keywordString.trim().split(/[, ]+/g) |
20 |
| - |
21 |
| - // Get rid of empty keywords |
22 |
| - result = result.filter(keyword => { |
23 |
| - return keyword |
24 |
| - }) |
25 |
| - |
26 |
| - return result |
27 |
| - }, |
28 |
| - set: function(words) { |
29 |
| - this.keywordString = words.join(',') |
30 |
| - } |
31 |
| - }, |
32 |
| - markdownPreview: function() { |
33 |
| - if (this.solution) { |
34 |
| - return marked(this.solution) |
35 |
| - } else { |
36 |
| - return '<p>Preview of markdown rendering of the solution</p>' |
37 |
| - } |
38 |
| - } |
39 |
| - }, |
40 |
| - template: ` |
41 |
| - <div class="add-form form-horizontal"> |
42 |
| - |
43 |
| - <div class="form-group"> |
44 |
| - <label for="problem" class="col-sm-2">Problem:</label> |
45 |
| - <div class="col-sm-10"> |
46 |
| - <input class="form-control" id="problem" type="text" v-model="problem"> |
47 |
| - </div> |
| 4 | + <div class="form-group"> |
| 5 | + <label for="problem" class="col-sm-2">Problem:</label> |
| 6 | + <div class="col-sm-10"> |
| 7 | + <input class="form-control" id="problem" type="text" v-model="problem"> |
48 | 8 | </div>
|
| 9 | + </div> |
49 | 10 |
|
50 |
| - <div class="form-group"> |
51 |
| - <label for="solution" class="col-sm-2">Solution:</label> |
52 |
| - <div class="col-sm-10"> |
53 |
| - <textarea class="form-control" id="solution" rows=10 cols=40 v-model="solution"></textarea> |
54 |
| - </div> |
| 11 | + <div class="form-group"> |
| 12 | + <label for="solution" class="col-sm-2">Solution:</label> |
| 13 | + <div class="col-sm-10"> |
| 14 | + <textarea class="form-control" id="solution" rows=10 cols=40 v-model="solution"></textarea> |
55 | 15 | </div>
|
| 16 | + </div> |
56 | 17 |
|
57 |
| - <div class="form-group"> |
58 |
| - <label for="keywords" class="col-sm-2">Keywords:</label> |
59 |
| - <div class="col-sm-10"> |
60 |
| - <input class="form-control" id="keywords" type="text" v-model="keywordString"> {{ keywords }} |
61 |
| - </div> |
| 18 | + <div class="form-group"> |
| 19 | + <label for="keywords" class="col-sm-2">Keywords:</label> |
| 20 | + <div class="col-sm-10"> |
| 21 | + <input class="form-control" id="keywords" type="text" v-model="keywordString"> {{ keywords }} |
62 | 22 | </div>
|
| 23 | + </div> |
63 | 24 |
|
64 |
| - <div class="form-group"> |
65 |
| - <div class="col-sm-offset-2 col-sm-10"> |
66 |
| - <button class="btn btn-primary" v-on:click="submit">Submit</button> |
67 |
| - </div> |
| 25 | + <div class="form-group"> |
| 26 | + <div class="col-sm-offset-2 col-sm-10"> |
| 27 | + <button class="btn btn-primary" v-on:click="submit">Submit</button> |
68 | 28 | </div>
|
69 |
| - |
70 |
| - <hr /> |
71 |
| - <div class="md" v-html="markdownPreview"></div> |
72 | 29 | </div>
|
73 |
| - `, |
74 |
| - methods: { |
75 |
| - submit: function() { |
76 |
| - if (!this.problem) { |
77 |
| - this.$emit('message', 'You gotta input a problem to add it, bro') |
78 |
| - } else if (!this.solution) { |
79 |
| - this.$emit( |
80 |
| - 'message', |
81 |
| - "It isn't very helpful to have a problem with no solution, now is it?" |
82 |
| - ) |
83 |
| - } else if (this.keywords.length == 0) { |
84 |
| - this.$emit('message', 'Keywords are your friend') |
85 |
| - } else { |
86 |
| - this.$emit('submit', { |
87 |
| - problem: this.problem, |
88 |
| - solution: this.solution, |
89 |
| - keywords: this.keywords |
90 |
| - }) |
| 30 | + |
| 31 | + <hr /> |
| 32 | + |
| 33 | + <div class="md" v-html="markdownPreview"></div> |
| 34 | + </div> |
| 35 | +</template> |
| 36 | + |
| 37 | +<script> |
| 38 | + const marked = require('marked') |
| 39 | +
|
| 40 | + module.exports = { |
| 41 | + props: ['problemProp', 'solutionProp', 'keywordStringProp'], |
| 42 | + data: function() { |
| 43 | + return { |
| 44 | + problem: this.problemProp || '', |
| 45 | + solution: this.solutionProp || '', |
| 46 | + keywordString: this.keywordStringProp || '' |
91 | 47 | }
|
92 | 48 | },
|
93 |
| - clear: function() { |
94 |
| - this.problem = '' |
95 |
| - this.solution = '' |
96 |
| - this.keywordString = '' |
| 49 | + computed: { |
| 50 | + keywords: { |
| 51 | + get: function() { |
| 52 | + let result |
| 53 | +
|
| 54 | + // Split into keywords |
| 55 | + result = this.keywordString.trim().split(/[, ]+/g) |
| 56 | +
|
| 57 | + // Get rid of empty keywords |
| 58 | + result = result.filter(keyword => { |
| 59 | + return keyword |
| 60 | + }) |
| 61 | +
|
| 62 | + return result |
| 63 | + }, |
| 64 | + set: function(words) { |
| 65 | + this.keywordString = words.join(',') |
| 66 | + } |
| 67 | + }, |
| 68 | + markdownPreview: function() { |
| 69 | + if (this.solution) { |
| 70 | + return marked(this.solution) |
| 71 | + } else { |
| 72 | + return '<p>Preview of markdown rendering of the solution</p>' |
| 73 | + } |
| 74 | + } |
97 | 75 | },
|
98 |
| - set: function(snippet) { |
99 |
| - this.problem = snippet.problem || this.problem |
100 |
| - this.solution = snippet.solution || this.solution |
101 |
| - this.keywordString = snippet.keywordString || this.keywordString |
102 |
| - this.keywords = snippet.keywords || this.keywords |
| 76 | + methods: { |
| 77 | + submit: function() { |
| 78 | + if (!this.problem) { |
| 79 | + this.$emit('message', 'You gotta input a problem to add it, bro') |
| 80 | + } else if (!this.solution) { |
| 81 | + this.$emit( |
| 82 | + 'message', |
| 83 | + "It isn't very helpful to have a problem with no solution, now is it?" |
| 84 | + ) |
| 85 | + } else if (this.keywords.length == 0) { |
| 86 | + this.$emit('message', 'Keywords are your friend') |
| 87 | + } else { |
| 88 | + this.$emit('submit', { |
| 89 | + problem: this.problem, |
| 90 | + solution: this.solution, |
| 91 | + keywords: this.keywords |
| 92 | + }) |
| 93 | + } |
| 94 | + }, |
| 95 | + clear: function() { |
| 96 | + this.problem = '' |
| 97 | + this.solution = '' |
| 98 | + this.keywordString = '' |
| 99 | + }, |
| 100 | + set: function(snippet) { |
| 101 | + this.problem = snippet.problem || this.problem |
| 102 | + this.solution = snippet.solution || this.solution |
| 103 | + this.keywordString = snippet.keywordString || this.keywordString |
| 104 | + this.keywords = snippet.keywords || this.keywords |
| 105 | + } |
103 | 106 | }
|
104 | 107 | }
|
105 |
| -}) |
106 |
| - |
107 |
| -module.exports = {} |
| 108 | +</script> |
0 commit comments