Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.js 4.4KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. Vue.component('search',{
  2. template: `
  3. <form class="om-searchbar" @submit.prevent="search()">
  4. <b-field>
  5. <b-autocomplete
  6. v-model="searchtext"
  7. @keydown.native.enter="search"
  8. :data="filteredDataArray"
  9. placeholder="suche..."
  10. icon="magnify"
  11. @select="option => selected = option">
  12. </b-autocomplete>
  13. <button class="clearButton" @click="clear">x</button>
  14. </b-field>
  15. </form>`,
  16. data: function() {
  17. return{
  18. searchtext: "",
  19. selected: [],
  20. taglist: data,
  21. };
  22. },
  23. computed:{
  24. filteredDataArray() {
  25. return this.taglist.filter((option) => {
  26. return option
  27. .toString()
  28. .toLowerCase()
  29. .indexOf(this.searchtext.toLowerCase()) >= 0
  30. })
  31. }
  32. },
  33. methods: {
  34. getFilteredTags(text) {
  35. this.taglist = data.filter((option) => {
  36. return option
  37. .toString()
  38. .toLowerCase()
  39. .indexOf(text.toLowerCase()) >= 0
  40. })
  41. this.search();
  42. },
  43. search: function() {
  44. searching(this.searchtext);
  45. },
  46. saveTagsToArray: function() {
  47. tagArray = this.selected;
  48. // console.info(tagArray);
  49. },
  50. list_messages: function() {
  51. messages();
  52. },
  53. list_tags: function () {
  54. $.ajax({url: "api/tag/ids", method: "GET"})
  55. .done(jd => {
  56. // NICHT SO wg. Vue: _messagelist = jd;
  57. if(data == ""){
  58. _taglist.splice(0, _taglist.length);
  59. _taglist.push.apply(_taglist, jd);
  60. // console.log("tag: jd: " + jd);
  61. for (var e in jd) {
  62. if (!_tags[jd[e]]) {
  63. get_insert_tag(jd[e]);
  64. }
  65. }
  66. }
  67. }).fail(function (e, f, g) {
  68. console.log("err: " + e + f + g);
  69. });
  70. },
  71. clear: function() {
  72. //_isSearchActiv = false;
  73. this.searchtext = "";
  74. this.list_messages();
  75. //router.push('/files')
  76. //router.push('/home')
  77. $("#escape-search-link").css("visibility", "hidden");
  78. $("#subscribe-btn").css("visibility", "hidden");
  79. },
  80. },
  81. mounted: function() {
  82. //this.search();
  83. this.list_tags();
  84. },
  85. });
  86. // Global Functions !!!
  87. function get_insert_tag(id) {
  88. $.ajax({
  89. url: "api/tag/id/" + id,
  90. method: "GET"
  91. }).done(function(tag) {
  92. data.push("#" + tag.name);
  93. }).fail(function(e, f, g) {
  94. console.log("cannot load " + id + ".json: " + e + f + g);
  95. })
  96. }
  97. function searching(searchtext) {
  98. _isSearchActiv = true;
  99. $("#escape-search-link").css("visibility", "visible");
  100. //console.log(_tags);
  101. console.log(data);
  102. if(data.indexOf(searchtext) > -1){
  103. var btnString = "#" + searchtext.replace(/#/g, '') + " abonnieren";
  104. $("#btn-text").text(btnString);
  105. $("#subscribe-btn").css("visibility", "visible");
  106. }else{
  107. $("#subscribe-btn").css("visibility", "hidden");
  108. }
  109. $.ajax({
  110. url: "api/msg/search/" + searchtext.replace(/#/g, ''),
  111. method: "GET"
  112. }).done(jd => {
  113. // NICHT SO wg. Vue: _messagelist = jd;
  114. _messagelist.splice(0, _messagelist.length);
  115. _messagelist.push.apply(_messagelist, jd);
  116. //console.log("jd: "+jd);
  117. for (var e in jd) {
  118. if (!_messages[jd[e]]) {
  119. get_insert_message(jd[e]);
  120. }
  121. }
  122. }).fail(function(e, f, g) {
  123. console.log("searching: err: " + e + f + g);
  124. })
  125. }
  126. function messages() {
  127. $.ajax({
  128. url: "api/msg/ids",
  129. method: "GET"
  130. })
  131. .done(jd => {
  132. // NICHT SO wg. Vue: _messagelist = jd;
  133. _messagelist.splice(0, _messagelist.length);
  134. _messagelist.push.apply(_messagelist, jd);
  135. //console.log("jd: "+jd);
  136. for (var e in jd) {
  137. if (!_messages[jd[e]]) {
  138. get_insert_message(jd[e]);
  139. }
  140. }
  141. }).fail(function(e, f, g) {
  142. console.log("list_msg: err: " + e + f + g);
  143. });
  144. }