-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a60124
commit 9fc4ff0
Showing
13 changed files
with
638 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from flask import Blueprint, render_template, url_for, session | ||
from flask_login import login_required | ||
import requests | ||
|
||
categories_blueprint = Blueprint('categories', __name__) | ||
|
||
@categories_blueprint.route('/categories') | ||
@login_required | ||
def categories(): | ||
""" | ||
Render the categories page. | ||
This view function fetches the categories from an external API and renders | ||
the categories/index.html template with the fetched categories and the user ID | ||
from the session. | ||
Returns: | ||
str: Rendered HTML template for the categories page. | ||
""" | ||
api_url = url_for('categories', _external=True) | ||
response = requests.get(api_url, timeout=15) | ||
_categories = response.json().get('categories', []) | ||
user_id = session.get('_user_id') | ||
return render_template('categories/index.html', categories=_categories, user_id=user_id) | ||
|
||
@categories_blueprint.route('/categories/group') | ||
@login_required | ||
def categories_group(): | ||
""" | ||
Fetch and return the categories group. | ||
This view function fetches the categories group from an external API and returns | ||
the categories group as a JSON response. | ||
Returns: | ||
list: List of categories group. | ||
""" | ||
api_url = url_for('categories_group', _external=True) | ||
response = requests.get(api_url, timeout=15) | ||
_categories_group = response.json().get('categories_group', []) | ||
user_id = session.get('_user_id') | ||
return render_template('categories/group.html', categories_group=_categories_group, user_id=user_id) | ||
|
||
@categories_blueprint.route('/categories/type') | ||
@login_required | ||
def categories_type(): | ||
""" | ||
Fetch and return the categories type. | ||
This view function fetches the categories type from an external API and returns | ||
the categories type as a JSON response. | ||
Returns: | ||
list: List of categories type. | ||
""" | ||
api_url = url_for('categories_type', _external=True) | ||
response = requests.get(api_url, timeout=15) | ||
_categories_type = response.json().get('categories_type', []) | ||
user_id = session.get('_user_id') | ||
return render_template('categories/type.html', categories_type=_categories_type, user_id=user_id) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function groupsFormSubmit(event) { | ||
event.preventDefault(); | ||
|
||
const groupName = document.getElementById('categoryGroupName').value; | ||
const user_id = document.getElementById('user_id').value; | ||
|
||
const data = { | ||
name: groupName, | ||
user_id: user_id | ||
}; | ||
|
||
fetch('/api/categories_group', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data), | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log('Success:', data); | ||
// redirect to the types page | ||
window.location.href = '/categories/group'; | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function typesFormSubmit(event) { | ||
event.preventDefault(); | ||
|
||
const typeName = document.getElementById('categoryTypeName').value; | ||
const user_id = document.getElementById('user_id').value; | ||
|
||
const data = { | ||
name: typeName, | ||
user_id: user_id | ||
}; | ||
|
||
fetch('/api/categories_type', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data), | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log('Success:', data); | ||
// redirect to the types page | ||
window.location.href = '/categories/type'; | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
{% extends "partials/base.html" %} | ||
{% block title %}Category Groups{% endblock title %} | ||
{% block extra_css %} | ||
{% endblock extra_css %} | ||
{% block content %} | ||
<div class="main-content"> | ||
|
||
<div class="page-content"> | ||
<div class="container-fluid"> | ||
|
||
<!-- start page title --> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div | ||
class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent"> | ||
<h4 class="mb-sm-0">Categories</h4> | ||
|
||
<div class="page-title-right"> | ||
<ol class="breadcrumb m-0"> | ||
<li class="breadcrumb-item"><a href="javascript: void(0);">Pages</a></li> | ||
<li class="breadcrumb-item active">Categories</li> | ||
</ol> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
<!-- end page title --> | ||
<div class="row"> | ||
<div class="col-xl-12"> | ||
<div class="card"> | ||
<div class="card-header align-items-center d-flex"> | ||
<h4 class="card-title mb-0 flex-grow-1">Groups</h4> | ||
|
||
<div class="flex-shrink-0"> | ||
<div class="hstack gap-2 "> | ||
<button type="button" class="btn btn-success btn-icon waves-effect waves-light" | ||
data-bs-toggle="modal" data-bs-target="#CategoriesModalgrid"><i | ||
class="ri-add-box-line"></i></button> | ||
<div class="live-preview"> | ||
<div class="modal fade" id="CategoriesModalgrid" tabindex="-1" | ||
aria-labelledby="CategoriesModalgridLabel"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="CategoriesModalgridLabel">Add | ||
Groups</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" | ||
aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<form action="" onsubmit="groupsFormSubmit(event)"> | ||
<input type="hidden" id="user_id" value="{{ user_id }}"> | ||
<div class="row g-3"> | ||
<div class="col-xxl-12"> | ||
<div> | ||
<label for="categoryGroupName" class="form-label">Category Group Name</label> | ||
<input type="text" class="form-control" | ||
id="categoryGroupName" | ||
placeholder="Enter Category Group Name"> | ||
</div> | ||
</div> | ||
<div class="col-lg-12"> | ||
<div class="hstack gap-2 justify-content-end"> | ||
<button type="button" class="btn btn-light" | ||
data-bs-dismiss="modal">Close</button> | ||
<button type="submit" | ||
class="btn btn-primary">Submit</button> | ||
</div> | ||
</div> | ||
<!--end col--> | ||
</div> | ||
<!--end row--> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div><!-- end card header --> | ||
|
||
|
||
|
||
<div class="card-body"> | ||
<p class="text-muted mb-4">Add Groups with the + button</p> | ||
|
||
<div class="live-preview"> | ||
<div class="table-responsive table-card"> | ||
<table class="table align-middle table-nowrap table-striped-columns mb-0"> | ||
<thead class="table-light"> | ||
<tr> | ||
<th scope="col" style="width: 46px;"> | ||
<div class="form-check"> | ||
<input class="form-check-input" type="checkbox" value="" | ||
id="cardtableCheck"> | ||
<label class="form-check-label" for="cardtableCheck"></label> | ||
</div> | ||
</th> | ||
<th scope="col">Name</th> | ||
|
||
<th scope="col" style="width: 150px;">Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for groups in categories_group %} | ||
<tr> | ||
<td> | ||
<div class="form-check"> | ||
<input class="form-check-input" type="checkbox" value="" | ||
id="cardtableCheck01"> | ||
<label class="form-check-label" for="cardtableCheck01"></label> | ||
</div> | ||
</td> | ||
|
||
<td>{{ groups.name }}</td> | ||
<td> | ||
<button type="button" class="btn btn-sm btn-light">Details</button> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div><!-- end card-body --> | ||
</div><!-- end card --> | ||
</div><!-- end col --> | ||
</div><!-- end row --> | ||
|
||
</div> | ||
<!-- container-fluid --> | ||
</div> | ||
|
||
{% block footer %} | ||
{% include "partials/footer.html" %} | ||
{% endblock footer %} | ||
</div> | ||
<!-- end main content--> | ||
{% endblock content %} | ||
{% block extra_js %} | ||
<script src="{{ url_for('static', filename='js/categories/group.js') }}"></script> | ||
{% endblock extra_js %} |
Oops, something went wrong.