app.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. var app = new Vue({
  13. el: '#app',
  14. data: {
  15. title: "GUNTRADER",
  16. queries: {},
  17. debug: false,
  18. account: false,
  19. new_account: "",
  20. search_visible: false,
  21. query: {
  22. url: null,
  23. search: null,
  24. maxprice: null,
  25. minprice: null,
  26. restricted: null,
  27. }
  28. },
  29. mounted: function () {
  30. // hide splash
  31. var splash = document.getElementById("splash");
  32. splash.style.display = "none";
  33. // unhide main container after mount
  34. this.$el.style.display = "block";
  35. this.account = window.location.hash.slice(1)
  36. // get_items();
  37. this.load_account();
  38. },
  39. computed: {
  40. query_url: {
  41. get() {
  42. if (this.query.search || this.query.maxprice || this.query.minprice || this.query.restricted) {
  43. var query = "http://www.egun.de/market/list_items.php?mode=qry&plusdescr=off";
  44. if (this.query.search) {query += "&query=" + this.query.search.replace(" ", "+");}
  45. if (this.query.restricted) {query += "&ewb=1";}
  46. if (this.query.maxprice) {query += "&maxprice=" + this.query.maxprice;}
  47. if (this.query.minprice) {query += "&minprice=" + this.query.minprice;}
  48. return query;
  49. } else {
  50. return this.query.url
  51. }
  52. },
  53. set(newVal){
  54. //this function will run whenever the input changes
  55. this.query.url = newVal;
  56. }
  57. }
  58. },
  59. methods: {
  60. load_account: function () {
  61. var self = this;
  62. fetch('load/' + self.account)
  63. .then(function(response) {
  64. return response.json();
  65. })
  66. .then(function(myJson) {
  67. self.queries = myJson;
  68. });
  69. },
  70. display_query: function (queryname) {
  71. let q = queryname.split("query=")[1].split("&")[0].replace(/[+]/g, " ")
  72. return q
  73. },
  74. add_query: function () {
  75. this.$set(this.queries, this.query_url, {});
  76. },
  77. delete_query: function (queryname) {
  78. this.$delete(this.queries, queryname);
  79. },
  80. save_account: function () {
  81. let account = {}
  82. account[this.account] = {queries: this.queries};
  83. console.log(JSON.stringify(account) );
  84. var self = this;
  85. console.log("Saving");
  86. fetch("http://localhost:8000/save", {
  87. method: "POST",
  88. body: JSON.stringify(account)
  89. }).then(res => {
  90. console.log("Request complete! response:", res);
  91. });
  92. }
  93. },
  94. watch: {
  95. },
  96. });