Advertisement
Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 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.  
  40. function convertDate(year, month, day) {
  41. let result = year + '-';
  42. if (month < 10) {
  43. result += '0' + month + '-';
  44. } else {
  45. result += month + '-';
  46. }
  47. if (day < 10) {
  48. result += '0' + day;
  49. } else {
  50. result += day;
  51. }
  52. return result;
  53. }
  54.  
  55. export default {
  56. name: 'main-page',
  57. components: {
  58. PersonMentionsTimetable,
  59. },
  60. data: function() {
  61. return {
  62. searchQuery: '',
  63. searchResults: ''
  64. }
  65. },
  66. watch: {
  67. searchResults: function(value) {
  68. if (value.length > 0) {
  69. this.$store.state.entitiesFound = value;
  70. } else {
  71. this.$store.state.entitiesFound = [];
  72. }
  73. }
  74. },
  75. created: function () {
  76. this.$store.dispatch('loadMainPageData');
  77. this.loadData();
  78. },
  79. computed: {
  80. isLoaded() {
  81. return !!this.$store.state.mainPageData;
  82. },
  83. isGraphNotLoaded() {
  84. return this.$store.state.graphData === null;
  85. },
  86. keywords() {
  87. return this.$store.state.mainPageData.keywords;
  88. },
  89. entities() {
  90. return this.$store.state.mainPageData.entities;
  91. },
  92. entitiesFound () {
  93. return this.$store.state.entitiesFound;
  94. },
  95. isDisplayLiveSearch () {
  96. return this.$store.state.entitiesFound.length !== 0;
  97. }
  98. },
  99. methods: {
  100. loadData(){
  101. console.log('load data');
  102. this.$store.state.graphData = null;
  103. let now = new Date();
  104. let prev = new Date(now - 7*1000*60*60*24);
  105. this.$store.state.time = {
  106. end: convertDate(now.getFullYear(), now.getMonth()+1, now.getDate()),
  107. begin: convertDate(now.getFullYear(), now.getMonth()+1, prev.getDate())
  108. };
  109. console.log('assigned date');
  110. this.$store.state.entityIds = [44,20,278,217,59,240,42,25,190,6];
  111. let params = {
  112. timeFrom: this.$store.state.time.begin,
  113. timeTo: this.$store.state.time.end,
  114. keywords: this.$store.state.filterKeys
  115. };
  116. console.log(params);
  117. this.$store.dispatch('loadGraphData', params);
  118.  
  119. /*this.$store.watch((state)=> state.mainPageData, () => {
  120. this.$store.dispatch('loadGraphData', params);
  121. });*/
  122. },
  123. getColor(color) {
  124. const colors = [
  125. "#FBF8B7",
  126. "#7F8B99",
  127. "#FFEFBE",
  128. "#62BABC"
  129. ];
  130. return colors[color % colors.length];
  131. },
  132. onEntityClick (entityId) {
  133. this.$store.state.entitiesFound = [];
  134. this.$store.state.isDisplayInput = true;
  135. this.$router.push('/profile/'+ entityId + '/');
  136. },
  137. onKeywordClick(keyword) {
  138. console.log('clicked');
  139. this.$store.state.filterKeys = [keyword]
  140. this.loadData();
  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. cursor: pointer;
  213. }
  214. .title {
  215. font-size: 25px;
  216. }
  217. .text {
  218. display: inline-block;
  219. margin: 2%;
  220. box-shadow: 0 0 4px;
  221. }
  222.  
  223. .entity:hover {
  224. cursor: pointer;
  225. }
  226.  
  227. #tooltip-list {
  228. z-index: 100;
  229. position: absolute;
  230. background: #eeeeee;
  231. font-size: 20px;
  232. text-align: left;
  233. width: 70%;
  234. left: 12.7%
  235. }
  236. .tooltip-entity {
  237. padding: 5px;
  238. border-bottom: 1px solid #DDDDDD;
  239. white-space: nowrap;
  240. overflow: hidden;
  241. text-overflow: ellipsis;
  242. }
  243. .tooltip-entity:hover {
  244. cursor: pointer;
  245. background: #FFEFBE;
  246. }
  247.  
  248. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement