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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. },
  76. },
  77. mounted: function() {
  78. //this.search();
  79. this.list_tags();
  80. },
  81. });
  82. // Global Functions !!!
  83. function get_insert_tag(id) {
  84. $.ajax({
  85. url: "api/tag/id/" + id,
  86. method: "GET"
  87. }).done(function(tag) {
  88. data.push("#" + tag.name);
  89. }).fail(function(e, f, g) {
  90. console.log("cannot load " + id + ".json: " + e + f + g);
  91. })
  92. }
  93. function searching(searchtext) {
  94. _isSearchActiv = true;
  95. console.log("Searchtext: " + searchtext.replace(/#/g, ''));
  96. $.ajax({
  97. url: "api/msg/search/" + searchtext.replace(/#/g, ''),
  98. method: "GET"
  99. }).done(jd => {
  100. // NICHT SO wg. Vue: _messagelist = jd;
  101. _messagelist.splice(0, _messagelist.length);
  102. _messagelist.push.apply(_messagelist, jd);
  103. //console.log("jd: "+jd);
  104. for (var e in jd) {
  105. if (!_messages[jd[e]]) {
  106. get_insert_message(jd[e]);
  107. }
  108. }
  109. }).fail(function(e, f, g) {
  110. console.log("searching: err: " + e + f + g);
  111. })
  112. _isSubscripeButtonActiv = (_taglist.indexOf(searchtext.replace(/#/g, '')) > -1);
  113. console.log("isSubscripeButtonActiv: " + _isSubscripeButtonActiv);
  114. }
  115. function messages() {
  116. $.ajax({
  117. url: "api/msg/ids",
  118. method: "GET"
  119. })
  120. .done(jd => {
  121. // NICHT SO wg. Vue: _messagelist = jd;
  122. _messagelist.splice(0, _messagelist.length);
  123. _messagelist.push.apply(_messagelist, jd);
  124. //console.log("jd: "+jd);
  125. for (var e in jd) {
  126. if (!_messages[jd[e]]) {
  127. get_insert_message(jd[e]);
  128. }
  129. }
  130. }).fail(function(e, f, g) {
  131. console.log("list_msg: err: " + e + f + g);
  132. });
  133. }