Skip to content

Commit fa85a4a

Browse files
committed
Added new getPathSplit function and updated all controllers to utilize it.
Updated list views to utilize query params.
1 parent 227f5c1 commit fa85a4a

10 files changed

Lines changed: 27 additions & 55 deletions

File tree

project_manager/static/project_manager/js/controllers/common.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
function getPathSplit(originalPath) {
2+
if (originalPath.startsWith("/")) {
3+
originalPath = originalPath.slice(1);
4+
}
5+
if (originalPath.endsWith("/")) {
6+
originalPath = originalPath.slice(0, -1);
7+
}
8+
return originalPath.split("/");
9+
}
10+
111
function isLongText(meta) {
212
return !!(meta.max_length && meta.max_length > 200);
313
}

project_manager/static/project_manager/js/controllers/create.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
window.onload = function(){
22
console.log('create')
3-
const urlSearchParams = new URLSearchParams(window.location.search);
4-
const params = Object.fromEntries(urlSearchParams.entries());
5-
let originalPath = window.location.pathname;
6-
if (originalPath.startsWith("/")) {
7-
originalPath = originalPath.slice(1);
8-
}
9-
if (originalPath.endsWith("/")) {
10-
originalPath = originalPath.slice(0, -1);
11-
}
12-
const pathStrSplit = originalPath.split("/");
3+
const pathStrSplit = getPathSplit(window.location.pathname);
134
const projectType = pathStrSplit[0];
145
if (projectType === 'plugins' || projectType === 'packages') {
156
if (pathStrSplit[1]) {

project_manager/static/project_manager/js/controllers/delete.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
window.onload = function(){
22
console.log('delete')
3-
const urlSearchParams = new URLSearchParams(window.location.search);
4-
const params = Object.fromEntries(urlSearchParams.entries());
5-
let originalPath = window.location.pathname;
6-
if (originalPath.startsWith("/")) {
7-
originalPath = originalPath.slice(1);
8-
}
9-
if (originalPath.endsWith("/")) {
10-
originalPath = originalPath.slice(0, -1);
11-
}
12-
const pathStrSplit = originalPath.split("/");
3+
const pathStrSplit = getPathSplit(window.location.pathname);
134
const projectType = pathStrSplit[0];
145
if (projectType === 'plugins' || projectType === 'packages') {
156
if (pathStrSplit[1]) {

project_manager/static/project_manager/js/controllers/edit.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
window.onload = function(){
22
console.log('edit')
3-
const urlSearchParams = new URLSearchParams(window.location.search);
4-
const params = Object.fromEntries(urlSearchParams.entries());
5-
let originalPath = window.location.pathname;
6-
if (originalPath.startsWith("/")) {
7-
originalPath = originalPath.slice(1);
8-
}
9-
if (originalPath.endsWith("/")) {
10-
originalPath = originalPath.slice(0, -1);
11-
}
12-
const pathStrSplit = originalPath.split("/");
3+
const pathStrSplit = getPathSplit(window.location.pathname);
134
const projectType = pathStrSplit[0];
145
if (projectType === 'plugins' || projectType === 'packages') {
156
if (pathStrSplit[1]) {

project_manager/static/project_manager/js/controllers/retrieve.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
window.onload = function(){
2-
const urlSearchParams = new URLSearchParams(window.location.search);
3-
const params = Object.fromEntries(urlSearchParams.entries());
4-
let originalPath = window.location.pathname;
5-
if (originalPath.startsWith("/")) {
6-
originalPath = originalPath.slice(1);
7-
}
8-
if (originalPath.endsWith("/")) {
9-
originalPath = originalPath.slice(0, -1);
10-
}
11-
const pathStrSplit = originalPath.split("/");
2+
const urlSearchParams = window.location.search;
3+
const pathStrSplit = getPathSplit(window.location.pathname);
124
const projectType = pathStrSplit[0];
135
let urlPath = "/api/" + projectType + "/projects/";
146
let projectSlug = pathStrSplit[1];
@@ -20,13 +12,14 @@ window.onload = function(){
2012
urlPath = urlPath + projectSlug + "/";
2113
showDetailView(urlPath);
2214
} else {
23-
showListView(urlPath);
15+
showListView(urlPath, urlSearchParams);
2416
}
2517
};
2618

27-
function showListView(urlPath) {
19+
function showListView(urlPath, urlSearchParams) {
2820
document.getElementById("list-view").style.display = "block";
29-
fetch(urlPath)
21+
const fullApiUrl = `${urlPath}${urlSearchParams}`
22+
fetch(fullApiUrl)
3023
.then(res => res.json())
3124
.then(data => {
3225
const container = document.getElementById("project-list");

project_manager/static/project_manager/js/controllers/update.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
window.onload = function(){
22
console.log('update')
3-
let originalPath = window.location.pathname;
4-
if (originalPath.startsWith("/")) {
5-
originalPath = originalPath.slice(1);
6-
}
7-
if (originalPath.endsWith("/")) {
8-
originalPath = originalPath.slice(0, -1);
9-
}
10-
const pathStrSplit = originalPath.split("/");
3+
const pathStrSplit = getPathSplit(window.location.pathname);
114
pathStrSplit.pop();
125
let urlPath;
136
const successUrlPath = "/" + pathStrSplit.join("/") + "/";

templates/base.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ <h1>Popular Tags</h1>
130130
</footer>
131131

132132
{% block load_scripts %}
133-
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
134-
<script src="{% static "project_manager/js/jquery.min.js" %}"></script>
135-
<script src="{% static "project_manager/js/bootstrap.js" %}"></script>
136-
<script src="{% static "project_manager/js/custom.js" %}"></script>
133+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
134+
<script src="{% static "project_manager/js/jquery.min.js" %}"></script>
135+
<script src="{% static "project_manager/js/bootstrap.js" %}"></script>
136+
<script src="{% static "project_manager/js/custom.js" %}"></script>
137137
{% endblock load_scripts %}
138138
</body>
139139

templates/delete.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{ title }}
66
{% endblock title %}
77
{% block load_scripts %}
8+
<script src="{% static "project_manager/js/controllers/common.js" %}"></script>
89
<script src="{% static "project_manager/js/controllers/delete.js" %}"></script>
910
{% endblock load_scripts %}
1011

templates/retrieve.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{ title }}
66
{% endblock title %}
77
{% block load_scripts %}
8+
<script src="{% static "project_manager/js/controllers/common.js" %}"></script>
89
<script src="{% static "project_manager/js/controllers/retrieve.js" %}"></script>
910
{% endblock load_scripts %}
1011

templates/update.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{ title }}
66
{% endblock title %}
77
{% block load_scripts %}
8+
<script src="{% static "project_manager/js/controllers/common.js" %}"></script>
89
<script src="{% static "project_manager/js/controllers/update.js" %}"></script>
910
{% endblock load_scripts %}
1011

0 commit comments

Comments
 (0)