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.1KB

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