diff --git a/frontend/chbase.sh b/frontend/chbase.sh new file mode 100755 index 00000000..161fb145 --- /dev/null +++ b/frontend/chbase.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# You can define the current base URL in your environment +[ -n "${CURRENT_BASE}" ] || CURRENT_BASE="/" + +usage() { + echo "$0 NEWBASE STATICDIR" + echo + echo " This script can be used to change the base URL of the frontend." + echo " Gives as PATH, the path to the static directory." + echo " You should use this script only one time (ie. from a fresh git repository)," + echo " as it doesn't erase previously defined base: it assumes the current base is /." + echo + echo " For example:" + echo + echo " $0 /$(date -d 'next year' +%Y)/" static/ + echo +} + +run() { + local NEWBASE=$1 + local FILE=$2 + + if [ -d "${FILE}" ] + then + for f in "${FILE}/"*.html "${FILE}/"*.js + do + run "${NEWBASE}" "${f}" + done + [ -d "${FILE}/js/" ] && run "${NEWBASE}" "${FILE}/js" + [ -d "${FILE}/views/" ] && run "${NEWBASE}" "${FILE}/views" + elif [ -f "${FILE}" ] + then + sed -ri "s@(href|src)=\"${CURRENT_BASE}@\1=\"${NEWBASE}@g;s@\\\$http.get\(\"${CURRENT_BASE}@\$http.get\(\"${NEWBASE}@g;s@\\\$http\((.*)\"${CURRENT_BASE}@\$http(\1\"${NEWBASE}@g" ${FILE} + fi +} + +if [ $# -gt 1 ] +then + run $1 $2 +else + usage + exit 1 +fi diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index 63757736..3568bb75 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -172,13 +172,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) $scope.hsubmit = function(hint) { hint.submitted = true; - $http({ - url: "/openhint/" + $rootScope.current_exercice, - method: "POST", - data: { - id: hint.id - } - }).success(function(data, status, header, config) { + $http({ url: "/openhint/" + $rootScope.current_exercice, method: "POST", data: { id: hint.id } }).success(function(data, status, header, config) { var checkDiffHint = function() { $http.get("/my.json").success(function(my) { angular.forEach(my.exercices[$rootScope.current_exercice].hints, function(h,hid){ @@ -231,11 +225,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) flgs[flag.name] = flag.value; }); - $http({ - url: "/submit/" + $rootScope.current_exercice, - method: "POST", - data: flgs - }).success(function(data, status, header, config) { + $http({ url: "/submit/" + $rootScope.current_exercice, method: "POST", data: flgs }).success(function(data, status, header, config) { $rootScope.messageClass = {"text-success": true}; $rootScope.message = data.errmsg; $rootScope.sberr = "";