-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
250 lines (235 loc) · 10.4 KB
/
index.html
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test vue</title>
<!--include bootstrap 4-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!--include my style's-->
<link rel="stylesheet" href="css/style.css">
<!--include lib axios-->
<script src="lib/axios.min.js"></script>
<!--include vue-->
<script src="lib/vue.js"></script>
</head>
<body>
<!--Post-->
<template id="post">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="card mt-2">
<div class="card-header">
<button type="button"
class="btn btn-secondary"
@click="$emit('close')"><- Back to posts</button>
</div>
<div class="card-body">
<h3 class="card-title">{{post.title}}</h3>
<p class="card-text">{{post.body}}.</p>
<h4>Comments <small>{{comments.length}}</small></h4>
<div class="comments-list">
<div class="media mt-3 pb-2" v-for="(comment, index) in comments">
<img :src="'http://lorempixel.com/40/40/people/' + index"
class="mr-3">
<div class="media-body">
<h5 class="mt-0">{{comment.name}} // {{comment.email}}</h5>
{{comment.body}}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<!--Template for pagination-->
<template id="pagination-template">
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center mt-3">
<!--button previous page-->
<li class="page-item" style="margin-right: 40px">
<a class="page-link"
v-if="hasPrev()"
href="#"
@click="changePage(prevPage)"
>Previous</a>
</li>
<!--fast transition to the first-->
<li v-if="hasFirst()" class="page-item" style="margin-right: 20px">
<a href="#" class="page-link" @click="changePage(1)">1</a>
</li>
<!--adjacent values left and right-->
<li class="page-item" v-for="page in pages">
<a href="#"
class="page-link"
:class="{ current: current == page }"
@click="changePage(page)">
{{page}}
</a>
</li>
<!--fast transition to the last-->
<li v-if="hasLast()" class="page-item" style="margin-left: 20px">
<a href="#" class="page-link" @click="changePage(totalPages)">{{totalPages}}</a>
</li>
<!--button next page-->
<li class="page-item" style="margin-left: 40px">
<a class="page-link" v-if="hasNext()" href="#" @click="changePage(nextPage)">Next</a>
</li>
</ul>
</nav>
</template>
<!--Template for modal comment-->
<template id="modal-comment-template">
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Comments: {{commentAll.length}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @click="$emit('close')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="comments-list">
<div class="media mt-3 pb-2" v-for="(comment, index) in commentAll">
<img :src="'http://lorempixel.com/40/40/people/' + index"
class="mr-3">
<div class="media-body">
<h5 class="mt-0">{{comment.name}} // {{comment.email}} </h5>
{{comment.body}}
<br>
<small>for postID: <cite title="Source Title">{{comment.postId}}</cite></small>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<!--Template for modal user-->
<template id="modal-user-template">
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @click="$emit('close')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h1 class="text-center">UserID = {{userId}}</h1>
</div>
</div>
</div>
</div>
</template>
<!--Template for create new post-->
<template id="create-post">
<div class="container">
<div class="row">
<div class="col-md-12">
<h3 class="mt-3">Create new post</h3>
<form class="mt-3">
<div class="form-group">
<label for="titlePost">Title post</label>
<input type="text" class="form-control" id="titlePost" v-model="titlePost">
<small style="color: red;" v-if="errors.title">Поле не заполнено</small>
</div>
<div class="form-group">
<label for="textPost">Text post</label>
<textarea class="form-control" id="textPost" rows="3" v-model="textPost"></textarea>
<small style="color: red;" v-if="errors.text">Поле не заполнено</small>
</div>
<div class="form-group">
<div class="mx-auto" style="width: 143px">
<button type="button"
class="btn btn-secondary"
@click="$emit('close')">
Cancel
</button>
<button type="button"
class="btn btn-primary"
@click="savePost">
Save
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</template>
<!--App-->
<div id="app">
<!--Component comment-->
<modal-comment v-if="modalComment"
@close="showModalComment"
:comment-all="comment"
>
</modal-comment>
<!--Component user-->
<modal-user v-if="modalUser"
@close="showModalUser"
:user-id="userId">
</modal-user>
<!--Component post-->
<post v-if="post"
@close="showPost"
:post="postValue"
:comments="postComment">
</post>
<!--Button create post-->
<div class="container" v-if="buttonCreatePost">
<div class="row mt-2 mb-2">
<button type="button"
class="btn btn-primary mx-auto"
@click="showCreatePost">
Create post
</button>
</div>
</div>
<!--Form for create new post-->
<create-post v-if="createPost"
@close="showCreatePost">
</create-post>
<!--Table for data-->
<table class="table" v-if="table">
<thead>
<tr>
<th scope="col" class="text-left">ID</th>
<th scope="col" class="text-center">Title</th>
<th scope="col" class="text-center">Comments</th>
<th scope="col" class="text-right">Author</th>
</tr>
</thead>
<tbody>
<tr v-for="post in currentPosts">
<th scope="row" class="text-left">{{post.id}}</th>
<td class="text-center"><a href="#" @click="showPost(post.id)">{{post.title}}</a></td>
<td class="text-center"><a href="#" @click="showModalComment(post.id)">Comments</a></td>
<td class="text-right"><a href="#" @click="showModalUser(post.userId)">Author [{{post.userId}}]</a></td>
</tr>
</tbody>
</table>
<!--Component pagination-->
<pagination
v-if="table"
:current="currentPage"
:total="totalPost"
:per-page="perPage"
@page-changed="fetchPosts">
</pagination>
</div>
<!--include script file-->
<script src="js/create-post.js"></script>
<script src="js/post.js"></script>
<script src="js/modal-comment.js"></script>
<script src="js/modal-user.js"></script>
<script src="js/pagination.js"></script>
<script src="js/main.js"></script>
</body>
</html>