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

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