Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-02-13 19:11:11 +0300
committerFilipa Lacerda <filipa@gitlab.com>2017-02-15 22:57:48 +0300
commit1285d629064abce3aee8faafaa57492da6f8f163 (patch)
tree29f6e73839bd7fadfd7f98a0223b955b2c0165c6 /app/assets/javascripts/lib
parent73accafe430f56cd3065774c6118de3db0a45734 (diff)
Move change page param to utility function
Add tests Adds folder name in the top of the table
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js.es640
1 files changed, 40 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js.es6 b/app/assets/javascripts/lib/utils/common_utils.js.es6
index bcb3a706b51..276ff01ab89 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js.es6
+++ b/app/assets/javascripts/lib/utils/common_utils.js.es6
@@ -241,5 +241,45 @@
acc[element] = DOMStringMapObject[element];
return acc;
}, {});
+
+ /**
+ * Updates the search parameter of a URL given the parameter and values provided.
+ *
+ * If no search params are present we'll add it.
+ * If param for page is already present, we'll update it
+ * If there are params but not for the given one, we'll add it at the end.
+ * Returns the new search parameters.
+ *
+ * @param {String} param
+ * @param {Number|String|Undefined|Null} value
+ * @return {String}
+ */
+ w.gl.utils.setParamInURL = (param, value) => {
+ let search;
+
+ if (window.location.search.length === 0) {
+ search = `?${param}=${value}`;
+ }
+
+ if (window.location.search.indexOf(param) !== -1) {
+ const regex = new RegExp(param + '=\\d');
+ search = window.location.search.replace(regex, `${param}=${value}`);
+ }
+
+ if (window.location.search.length &&
+ window.location.search.indexOf(param) === -1) {
+ search = `${window.location.search}&${param}=${value}`;
+ }
+
+ return search;
+ };
+
+ /**
+ * Converts permission provided as strings to booleans.
+ *
+ * @param {String} string
+ * @returns {Boolean}
+ */
+ w.gl.utils.convertPermissionToBoolean = permission => permission === 'true';
})(window);
}).call(this);