Advertisement
Guest User

Untitled

a guest
May 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. <template>
  2. <div key="not-loaded" v-if="!isLoaded"></div>
  3. <div key="loaded" v-else>
  4. <div class="triangles">
  5. <div class="search">
  6. <input class="input" type="text" v-model="searchQuery" v-on:keyup.enter="search" v-on:input="search">
  7. <input type="button" class="button" value="Найти" @click="search">
  8. </div>
  9. <div id="tooltip-list" v-if="isDisplayLiveSearch">
  10. <div v-for="entity in entitiesFound" @click="onEntityClick(entity.id)" class="tooltip-entity">
  11. {{ entity.name }}
  12. </div>
  13. </div>
  14. <div v-else></div>
  15. <div class="flex-data">
  16. <div class ="flex-item">
  17. <div class="title">Популярные ключевые слова</div>
  18. <div v-for="(keyword, index) in keywords" @click="onKeywordClick(keyword)" :style="{ background: getColor(index) }" class="text">
  19. {{ keyword.word }}
  20. </div>
  21. </div>
  22. <div class ="flex-item">
  23. <div class="title">Популярные сущности</div>
  24. <div v-for="(entity, index) in entities" :style="{ background: getColor(index) }" class="text entity"
  25. @click="onEntityClick(entity.id)">
  26. {{ entity.name }}
  27. </div>
  28. </div>
  29. </div>
  30. <div v-if="isGraphNotLoaded">Loading</div>
  31. <person-mentions-timetable v-else>
  32. </person-mentions-timetable>
  33. </div>
  34. </div>
  35. </template>
  36.  
  37. <script>
  38. import PersonMentionsTimetable from "./PersonMentionsTimetable.vue";
  39. function convertDate(year, month, day) {
  40. let result = year + '-';
  41. if (month < 10) {
  42. result += '0' + month + '-';
  43. } else {
  44. result += month + '-';
  45. }
  46. if (day < 10) {
  47. result += '0' + day;
  48. } else {
  49. result += day;
  50. }
  51. return result;
  52. }
  53.  
  54. export default {
  55. name: 'main-page',
  56. components: {
  57. PersonMentionsTimetable,
  58. },
  59. data: function() {
  60. return {
  61. searchQuery: '',
  62. searchResults: ''
  63. }
  64. },
  65. watch: {
  66. searchResults: function(value) {
  67. if (value.length > 0) {
  68. this.$store.state.entitiesFound = value;
  69. } else {
  70. this.$store.state.entitiesFound = [];
  71. }
  72. }
  73. },
  74. created: function () {
  75. this.$store.dispatch('loadMainPageData');
  76. this.loadData();
  77. },
  78. computed: {
  79. isLoaded() {
  80. return !!this.$store.state.mainPageData;
  81. },
  82. isGraphNotLoaded() {
  83. return this.$store.state.graphData === null;
  84. },
  85. keywords() {
  86. return this.$store.state.mainPageData.keywords;
  87. },
  88. entities() {
  89. return this.$store.state.mainPageData.entities;
  90. },
  91. entitiesFound () {
  92. return this.$store.state.entitiesFound;
  93. },
  94. isDisplayLiveSearch () {
  95. return this.$store.state.entitiesFound.length !== 0;
  96. }
  97. },
  98. methods: {
  99. loadData(){
  100. this.$store.state.graphData = null;
  101. let now = new Date();
  102. let prev = new Date(now - 7*1000*60*60*24);
  103. this.$store.state.time = {
  104. end: convertDate(now.getFullYear(), now.getMonth()+1, now.getDate()),
  105. begin: convertDate(now.getFullYear(), now.getMonth()+1, prev.getDate())
  106. };
  107. this.$store.state.entityIds = [44,20,278,217,59,240,42,25,190,6];
  108. let params = {
  109. timeFrom: this.$store.state.time.begin,
  110. timeTo: this.$store.state.time.end,
  111. keywords: this.$store.state.filterKeys
  112. };
  113. this.$store.watch((state)=> state.mainPageData, () => {
  114.  
  115.  
  116. this.$store.dispatch('loadGraphData', params);
  117. });
  118. },
  119. getColor(color) {
  120. const colors = [
  121. "#FBF8B7",
  122. "#7F8B99",
  123. "#FFEFBE",
  124. "#62BABC"
  125. ];
  126. return colors[color % colors.length];
  127. },
  128. onEntityClick (entityId) {
  129. this.$store.state.entitiesFound = [];
  130. this.$store.state.isDisplayInput = true;
  131. this.$router.push('/profile/'+ entityId + '/');
  132. },
  133. onKeywordClick(keyword) {
  134. let filters = this.$store.state.filterKeys;
  135. let index = filters.map(key => key.id).indexOf(keyword.id);
  136. if (index === -1) {
  137. filters.push(keyword);
  138. this.$store.state.filterKeys = filters;
  139. this.loadData();
  140. }
  141. },
  142. search() {
  143. if (this.searchQuery === '') {
  144. this.$store.state.entitiesFound = [];
  145. return;
  146. }
  147. let this_ = this;
  148. $.ajax({
  149. url: '/search/' + this.searchQuery,
  150. type: 'GET',
  151. dataType: 'json',
  152. success: function (response) {
  153. this_.searchResults = response.matched;
  154. },
  155. error: function (jqXHR, e, errorMessage) {
  156. console.log('Unable to load search results: ' + errorMessage);
  157. }
  158. });
  159. }
  160. }
  161. }
  162.  
  163. </script>
  164.  
  165. <style scoped>
  166.  
  167. .triangles {
  168. background-image: url(/static/drawable/main.png);
  169. background-size: 55%;
  170. background-repeat: no-repeat;
  171. background-position-x: center;
  172. z-index: 1;
  173. }
  174.  
  175. .logo {
  176. background-image: url(/static/drawable/logo.png);
  177. width: 5.7%;
  178. height: 70px;
  179. background-size: 100%;
  180. background-repeat: no-repeat;
  181. }
  182.  
  183. .search {
  184. padding-top: 15%;
  185. text-align: center;
  186. }
  187.  
  188. .input {
  189. border-radius: 0;
  190. width: 70%;
  191. font-size: 20px;
  192. border: 1px solid black;
  193. }
  194.  
  195. .button {
  196. background-color: #78B7BB;
  197. font-size: 24px;
  198. border: 1px solid black;
  199. }
  200.  
  201. .flex-data {
  202. display: flex;
  203. }
  204.  
  205. .flex-item {
  206. padding: 140px;
  207. padding-left: 10%;
  208. padding-right: 10%;
  209. text-align: center;
  210. font-size: 20px;
  211. width: 50%;
  212. }
  213. .title {
  214. font-size: 25px;
  215. }
  216. .text {
  217. display: inline-block;
  218. margin: 2%;
  219. box-shadow: 0 0 4px;
  220. }
  221.  
  222. .entity:hover {
  223. cursor: pointer;
  224. }
  225.  
  226. #tooltip-list {
  227. z-index: 100;
  228. position: absolute;
  229. background: #eeeeee;
  230. font-size: 20px;
  231. text-align: left;
  232. width: 70%;
  233. left: 12.7%
  234. }
  235. .tooltip-entity {
  236. padding: 5px;
  237. border-bottom: 1px solid #DDDDDD;
  238. white-space: nowrap;
  239. overflow: hidden;
  240. text-overflow: ellipsis;
  241. }
  242. .tooltip-entity:hover {
  243. cursor: pointer;
  244. background: #FFEFBE;
  245. }
  246.  
  247. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement