From: Benjamin Auder Date: Tue, 22 Jan 2019 18:40:27 +0000 (+0100) Subject: Ready to translate old client code (start with index) X-Git-Url: https://git.auder.net/variants/Chakart/doc/css/current/scripts/common.css?a=commitdiff_plain;h=03470390eba8fd75b6aa5d929140d16a4aa719b9;p=vchess.git Ready to translate old client code (start with index) --- diff --git a/client/client_OLD/javascripts/app.js b/client/client_OLD/javascripts/app.js deleted file mode 100644 index 28c086b9..00000000 --- a/client/client_OLD/javascripts/app.js +++ /dev/null @@ -1,17 +0,0 @@ -// TODO: -//à l'arrivée sur le site : set peerID (un identifiant unique en tout cas...) si pas trouvé -// -//TODO: si une partie en cours dans storage, rediriger vers cette partie -//(à condition que l'URL n'y corresponde pas déjà !) - - - created - script. - const variant = !{JSON.stringify(variant)}; - // Just 'V' because this variable is often used: - const V = eval(variant.name + "Rules"); - - -mounted: function() { - feather.replace(); -} diff --git a/client/src/components/TestComp.vue b/client/src/components/TestComp.vue index 5f29c3ff..71793bf1 100644 --- a/client/src/components/TestComp.vue +++ b/client/src/components/TestComp.vue @@ -22,6 +22,10 @@ export default { // .then((V) => { // console.log(V); // }); + //console.log(this.$variants); + + // TODO: components which need to access user.name and user.id should + // import a module with a function to get this from localStorage (or anonymous) }, methods: { //... diff --git a/client/src/main.js b/client/src/main.js index 0b9b4023..e68447ee 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -1,6 +1,7 @@ import Vue from "vue"; import App from "./App.vue"; import router from "./router"; +import params from "./parameters"; //for socket connection import { ajax } from "./utils/ajax"; Vue.config.productionTip = false; @@ -12,11 +13,24 @@ new Vue({ }, created: function() { //alert("test"); - ajax("http://localhost:3000/variants", "GET", variantArray => { - console.log("Got variants:"); - console.log(variantArray); + ajax("/variants", "GET", res => { + Vue.prototype.$variants = res.variantArray; }); + Vue.prototype.$conn = null; //TODO + const myid = localStorage["myid"] || util.getRandString(); + // NOTE: in this version, we don't say on which page we are, yet + // ==> we'll say "enter/leave" page XY (in fact juste "enter", seemingly) + Vue.prototype.$conn = new WebSocket(params.socketUrl + "/?sid=" + myid); + //TODO: si une partie en cours dans storage, rediriger vers cette partie + //(à condition que l'URL n'y corresponde pas déjà !) + // TODO: à l'arrivée sur le site : set peerID (un identifiant unique + // en tout cas...) si pas trouvé dans localStorage "myid" + // (l'identifiant de l'utilisateur si connecté) }, + // Later, for icons (if using feather): +// mounted: function() { +// feather.replace(); +// }, }).$mount("#app"); // TODO: get rules, dynamic import @@ -25,3 +39,15 @@ new Vue({ // const lang = selectLanguage(req, res); // res.render("rules/" + req.params["vname"] + "/" + lang); // }); +// +// board2, 3, 4 automatiquement, mais rules separement (les 3 pour une) +// game : aussi systématique +// problems: on-demand +// +// It works (to watch for route change), in a component: +//watch: { +// $route: function(newRoute) { +// console.log(this.$route.params); +// }, +//}, +// See https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes diff --git a/client/src/parameters.js b/client/src/parameters.js new file mode 100644 index 00000000..f44a7d97 --- /dev/null +++ b/client/src/parameters.js @@ -0,0 +1,8 @@ +const Parameters = +{ + socketUrl: "ws://localhost:3000", + + serverUrl: "http://localhost:3000", +}; + +export default Parameters; diff --git a/client/src/parameters.js.dist b/client/src/parameters.js.dist new file mode 100644 index 00000000..34b57e6b --- /dev/null +++ b/client/src/parameters.js.dist @@ -0,0 +1,10 @@ +const Parameters = +{ + // URL of your socket server + socketUrl: "ws://localhost:3000", + + // URL of the server (leave blank for 1-server case) + serverUrl: "http://localhost:3000", +}; + +export default Parameters; diff --git a/client/src/socket_url.js.dist b/client/src/socket_url.js.dist deleted file mode 100644 index e3c0971c..00000000 --- a/client/src/socket_url.js.dist +++ /dev/null @@ -1,2 +0,0 @@ -// URL of your socket server (rename into socket_url.js) -export default socketUrl = "ws://localhost:3000"; diff --git a/client/src/utils/ajax.js b/client/src/utils/ajax.js index 065f3825..46edca06 100644 --- a/client/src/utils/ajax.js +++ b/client/src/utils/ajax.js @@ -1,3 +1,5 @@ +import params from "../parameters"; //for server URL + // From JSON (encoded string values!) to "arg1=...&arg2=..." function toQueryString(data) { @@ -42,7 +44,7 @@ export function ajax(url, method, data, success, error) // Append query params to URL url += "/?" + toQueryString(data); } - xhr.open(method, url, true); + xhr.open(method, params.serverUrl + url, true); xhr.setRequestHeader('X-Requested-With', "XMLHttpRequest"); if (["POST","PUT"].includes(method)) {