-
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.
Showing
12 changed files
with
619 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# coding: utf-8 | ||
|
||
# pylint: disable=missing-docstring | ||
# pylint: disable=logging-format-interpolation | ||
# pylint: disable=line-too-long | ||
# pylint: disable=invalid-name | ||
# pylint: disable=broad-except | ||
# pylint: disable=logging-fstring-interpolation, consider-using-f-string | ||
|
||
import logging | ||
# import traceback | ||
import json | ||
|
||
import flask_tracker.models | ||
|
||
from flask_restful import Resource, Api # pylint: disable=import-error | ||
from flask import Response # pylint: disable=import-error | ||
|
||
URL_PREFIX = '/api/v1/' | ||
DB_SESSION = None | ||
|
||
|
||
def frmt_model_obj(model_obj, excluded_fields, | ||
include_relationship=0, worktimes=False, milestone=False): | ||
model_json_str = model_obj.object_to_json( | ||
include_relationship=include_relationship, | ||
excluded_fields=excluded_fields | ||
) | ||
|
||
model_dict = json.loads(model_json_str) | ||
if worktimes: | ||
wtimes = model_dict.get('worktimes') | ||
model_dict['worktimes'] = sum([float(wt.get('duration')) for wt in wtimes]) | ||
if milestone: | ||
milestn = model_dict.get('milestone') | ||
model_dict['milestone'] = milestn.get('name') if milestn else None | ||
model_dict['project_id'] = milestn.get('project_id') if milestn else None | ||
# t_json_str = json.dumps(t_dict, indent = 4) | ||
|
||
return model_dict | ||
|
||
|
||
class TaskApi(Resource): | ||
|
||
def get(self): | ||
|
||
excluded_fields = ['followers', 'description', 'attachments', 'content', 'resources', 'modifications', 'lesson_learned'] | ||
tasks_db = DB_SESSION.query(flask_tracker.models.Task) | ||
tasks = [frmt_model_obj(t, excluded_fields, include_relationship=1, worktimes=True, milestone=True) | ||
for t in tasks_db] | ||
logging.warning(f'tasks({type(tasks)})') | ||
|
||
response = { | ||
"results": tasks | ||
} | ||
|
||
response_json = json.dumps(response, indent = 4) | ||
|
||
return Response(response_json, mimetype="application/json", status=200) | ||
|
||
|
||
class ProjectApi(Resource): | ||
|
||
def get(self): | ||
|
||
projects_db = DB_SESSION.query(flask_tracker.models.Project) | ||
projects = [frmt_model_obj(p, []) | ||
for p in projects_db] | ||
logging.warning(f'projects({type(projects)})') | ||
|
||
response = { | ||
"results": projects | ||
} | ||
|
||
response_json = json.dumps(response, indent = 4) | ||
|
||
return Response(response_json, mimetype="application/json", status=200) | ||
|
||
|
||
def init_restless_api(app, db): | ||
|
||
# creating APIs using flask_restful library | ||
_api = Api(app) | ||
|
||
global DB_SESSION # pylint: disable=global-statement | ||
if DB_SESSION is None: | ||
DB_SESSION = db.session | ||
|
||
_api.add_resource(TaskApi, URL_PREFIX + 'task') | ||
_api.add_resource(ProjectApi, URL_PREFIX + 'project') |
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
Large diffs are not rendered by default.
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,88 @@ | ||
/*.tab { | ||
overflow: hidden; | ||
border: 1px solid #ccc; | ||
background-color: #f1f1f1; | ||
} | ||
.tab button { | ||
background-color: inherit; | ||
float: left; | ||
border: none; | ||
outline: none; | ||
cursor: pointer; | ||
padding: 14px 16px; | ||
transition: 0.3s; | ||
} | ||
.tab button:hover { | ||
background-color: #ddd; | ||
} | ||
.tab button.active { | ||
background-color: #ccc; | ||
} | ||
.tabcontent { | ||
display: none; | ||
padding: 6px 12px; | ||
border: 1px solid #ccc; | ||
border-top: none; | ||
height: 90vh; | ||
}*/ | ||
|
||
/* TABLE CSS*/ | ||
|
||
#table-status-tasks{ | ||
margin-top: 20px; | ||
} | ||
|
||
.table-status-tasks-td{ | ||
border: 3px solid #dddddd; | ||
text-align: left; | ||
padding: 8px; | ||
} | ||
|
||
/* SIDE NAV */ | ||
.sidenav { | ||
height: 100%; | ||
width: 160px; | ||
position: fixed; | ||
z-index: 1; | ||
top: 0; | ||
left: 0; | ||
background-color: #111; | ||
overflow-x: hidden; | ||
padding-top: 20px; | ||
} | ||
|
||
.sidenav a { | ||
padding: 6px 8px 6px 16px; | ||
text-decoration: none; | ||
font-size: 25px; | ||
color: #818181; | ||
display: block; | ||
} | ||
|
||
.sidenav a:hover { | ||
color: #f1f1f1; | ||
} | ||
|
||
|
||
|
||
.flex-container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin-left: 165px; | ||
width: 70% | ||
} | ||
|
||
#filters { | ||
margin-top: 35px; | ||
margin-left: 165px; | ||
display: none; | ||
/*display: inline-block;*/ | ||
} | ||
|
||
.filters_btn { | ||
display: inline-block; | ||
} |
Oops, something went wrong.