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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if(_taglist.indexOf(searchtext.replace(/#/g, '')) > -1){
  101. var btnString = "#" + searchtext.replace(/#/g, '') + " abonnieren";
  102. $("#btn-text").text(btnString);
  103. $("#subscribe-btn").css("visibility", "visible");
  104. }else{
  105. $("#subscribe-btn").css("visibility", "hidden");
  106. }
  107. $.ajax({
  108. url: "api/msg/search/" + searchtext.replace(/#/g, ''),
  109. method: "GET"
  110. }).done(jd => {
  111. // NICHT SO wg. Vue: _messagelist = jd;
  112. _messagelist.splice(0, _messagelist.length);
  113. _messagelist.push.apply(_messagelist, jd);
  114. //console.log("jd: "+jd);
  115. for (var e in jd) {
  116. if (!_messages[jd[e]]) {
  117. get_insert_message(jd[e]);
  118. }
  119. }
  120. }).fail(function(e, f, g) {
  121. console.log("searching: err: " + e + f + g);
  122. })
  123. }
  124. function messages() {
  125. $.ajax({
  126. url: "api/msg/ids",
  127. method: "GET"
  128. })
  129. .done(jd => {
  130. // NICHT SO wg. Vue: _messagelist = jd;
  131. _messagelist.splice(0, _messagelist.length);
  132. _messagelist.push.apply(_messagelist, jd);
  133. //console.log("jd: "+jd);
  134. for (var e in jd) {
  135. if (!_messages[jd[e]]) {
  136. get_insert_message(jd[e]);
  137. }
  138. }
  139. }).fail(function(e, f, g) {
  140. console.log("list_msg: err: " + e + f + g);
  141. });
  142. }