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

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