app.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Number.prototype.currency = function() { return '$' + this.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') };
  2. function seconds_to_time(s) {
  3. var duration = moment.duration(s, 'seconds');
  4. return duration.format("DD-hh:mm");
  5. }
  6. function ts_to_remaining(ts) {
  7. return moment.unix(ts).fromNow();
  8. }
  9. function log() {
  10. console.log('LOG >>>', arguments);
  11. }
  12. // function get_items() {
  13. // fetch('load/' + app.account)
  14. // .then(function(response) {
  15. // return response.json();
  16. // })
  17. // .then(function(myJson) {
  18. // app.queries = myJson;
  19. // });
  20. // }
  21. var app = new Vue({
  22. el: '#app',
  23. data: {
  24. title: "egunner",
  25. queries: {},
  26. debug: false,
  27. account: false,
  28. new_account: "",
  29. search_visible: false,
  30. query: {
  31. url: null,
  32. search: null,
  33. maxprice: null,
  34. minprice: null,
  35. restricted: null,
  36. }
  37. },
  38. mounted: function () {
  39. // hide splash
  40. var splash = document.getElementById("splash");
  41. splash.style.display = "none";
  42. // unhide main container after mount
  43. this.$el.style.display = "block";
  44. this.account = window.location.hash.slice(1)
  45. // get_items();
  46. this.load_account();
  47. },
  48. computed: {
  49. query_url: {
  50. get() {
  51. if (this.query.search || this.query.maxprice || this.query.minprice || this.query.restricted) {
  52. var query = "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off";
  53. if (this.query.search) {query += "&query=" + this.query.search.replace(" ", "+");}
  54. if (this.query.restricted) {query += "&ewb=1";}
  55. if (this.query.maxprice) {query += "&maxprice=" + this.query.maxprice;}
  56. if (this.query.minprice) {query += "&minprice=" + this.query.minprice;}
  57. return query;
  58. } else {
  59. return this.query.url
  60. }
  61. },
  62. set(newVal){
  63. //this function will run whenever the input changes
  64. this.query.url = newVal;
  65. }
  66. }
  67. },
  68. methods: {
  69. load_account: function () {
  70. var self = this;
  71. fetch('load/' + self.account)
  72. .then(function(response) {
  73. return response.json();
  74. })
  75. .then(function(myJson) {
  76. self.queries = myJson;
  77. });
  78. },
  79. display_query: function (queryname) {
  80. let q = queryname.split("query=")[1].split("&")[0].replace(/[+]/g, " ")
  81. return q
  82. },
  83. add_query: function () {
  84. this.$set(this.queries, this.query_url, {});
  85. },
  86. delete_query: function (queryname) {
  87. this.$delete(this.queries, queryname);
  88. },
  89. save_query: function () {
  90. let account = {}
  91. account[this.account] = {queries: this.queries};
  92. console.log(JSON.stringify(account) );
  93. // this.account: {
  94. // queries: this.queries
  95. // }
  96. // };
  97. var self = this;
  98. console.log("Saving");
  99. fetch("http://localhost:8000/save", {
  100. method: "POST",
  101. body: JSON.stringify(account)
  102. }).then(res => {
  103. console.log("Request complete! response:", res);
  104. });
  105. }
  106. },
  107. watch: {
  108. },
  109. });
  110. // window.setInterval(function(){
  111. // // console.log('refresh');
  112. // // get_items();
  113. // app.load_account()
  114. // }, 5000);