Commit c5bc3ad8 by Damien Moulard

WIP: member points history

parent a48e0efe
......@@ -114,3 +114,5 @@ DISPLAY_COL_AUTRES = False
BLOCK_SERVICE_EXCHANGE_24H_BEFORE = True
# URL to the metabase dashboard for orders helper
ORDERS_HELPER_METABASE_URL = "https://metabase.lacagette-coop.fr/dashboard/16"
# New members space
START_DATE_FOR_POINTS_HISTORY = "2018-01-01"
\ No newline at end of file
function init_my_shifts() {
console.log('hello my services');
/**
* if no incoming_services || no history {
* if no incoming : load incoming
* if no history : load hitstory
* } else {
* do the stuff
* }
*/
}
\ No newline at end of file
......@@ -2,4 +2,4 @@ from django.apps import AppConfig
class MembersSpaceConfig(AppConfig):
name = 'members-space'
name = 'members_space'
......@@ -10,3 +10,18 @@ class CagetteMembersSpace(models.Model):
def __init__(self):
"""Init with odoo id."""
self.o_api = OdooAPI()
def get_points_history(self, partner_id, limit, date_from):
""" Get partner points history with related shift registration if needed """
cond = [
['partner_id', '=', partner_id],
['type', '=', 'ftop'],
['create_date', '>', date_from]
]
f = ['create_date', 'create_uid', 'shift_id', 'name', 'point_qty']
# TODO get related data in service registration
return self.o_api.search_read('shift.counter.event', cond, f, limit=limit, offset=0,
order='create_date DESC')
\ No newline at end of file
#my_shifts {
font-size: 1.8rem;
}
#incoming_services {
height: 100%;
flex-direction: column;
}
.history_table {
width: 100%;
}
.history_table_header {
display: flex;
border-bottom: 1px solid #333;
}
.history_table_line {
display: flex;
}
.table_header_el {
flex: 1 0 20%;
padding: 1rem 0.5rem;
font-weight: bold;
}
.table_line_el {
flex: 1 0 20%;
padding: 1rem 0.5rem;
border-bottom: 1px solid #e7e9ed;
}
\ No newline at end of file
......@@ -24,6 +24,11 @@ body {
box-shadow: 2px 2px 3px rgba(10,10,10,.1),0 0 0 1px rgba(10,10,10,.1);
}
.full_width_tile {
flex: 1 0 90%;
min-height: 100px;
}
.tile_title {
display: flex;
justify-content: center;
......@@ -41,11 +46,11 @@ body {
display: flex;
}
#tile_services_exchange .tile_content {
#home_tile_services_exchange .tile_content {
justify-content: center;
}
#tile_my_services .tile_content {
#home_tile_my_services .tile_content {
height: 100%;
flex-direction: column;
}
......
function init_my_shifts_tile() {
if (incoming_shifts.length === 0) {
$("#tile_my_services #home_incoming_services").text("Aucun service à venir...")
$("#home_tile_my_services #home_incoming_services").text("Aucun service à venir...")
} else {
$("#tile_my_services #home_incoming_services").empty();
let shift_line_template = $("#shift_line_template");
$("#home_tile_my_services #home_incoming_services").empty();
let cpt = 0;
for (shift of incoming_shifts) {
if (cpt === 3) {
break;
} else {
let datetime_shift_start = new Date(shift.date_begin);
let f_date_shift_start = datetime_shift_start.toLocaleDateString("fr-fr", date_options);
f_date_shift_start = f_date_shift_start.charAt(0).toUpperCase() + f_date_shift_start.slice(1);
shift_line_template.find(".shift_line_date").text(f_date_shift_start);
shift_line_template.find(".shift_line_time").text(datetime_shift_start.toLocaleTimeString("fr-fr"));
$("#tile_my_services #home_incoming_services").append(shift_line_template.html());
let shift_line_template = prepare_shift_line_template(shift.date_begin);
$("#home_tile_my_services #home_incoming_services").append(shift_line_template.html());
cpt++;
}
......
/**
* Load the partner points history
*/
function load_partner_history() {
return new Promise((resolve) => {
$.ajax({
type: 'GET',
url: "/members_space/get_points_history",
data: {
partner_id: partner_data.partner_id,
verif_token: partner_data.verif_token,
limit: 10
},
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
partner_history = data.data;
resolve();
},
error: function(data) {
err = {msg: "erreur serveur lors de la récupération des services", ctx: 'load_partner_shifts'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'members_space.index');
closeModal();
// TODO Notify
alert('Erreur lors de la récupération de vos services.');
}
});
});
}
function init_history() {
if (incoming_shifts.length === 0) {
$("#history").empty().text("Aucun historique... pour l'instant !")
} else {
for (history_item of partner_history) {
// Prepare history lines
let history_line_template = $("#history_line_template");
// Date
let datetime_item_start = new Date(history_item.create_date);
let f_date_item_start = datetime_item_start.toLocaleDateString("fr-fr", date_options);
f_date_item_start = f_date_item_start.charAt(0).toUpperCase() + f_date_item_start.slice(1);
history_line_template.find(".table_line_date").text(f_date_item_start);
history_line_template.find(".table_line_desc").text(history_item.name);
history_line_template.find(".table_line_pts").text(history_item.point_qty);
$(".history_table_content").append(history_line_template.html());
}
}
}
function init_incoming_shifts() {
if (incoming_shifts.length === 0) {
$("#incoming_services").text("Aucun service à venir...")
} else {
$("#incoming_services").empty();
for (shift of incoming_shifts) {
let shift_line_template = prepare_shift_line_template(shift.date_begin);
$("#incoming_services").append(shift_line_template.html());
}
}
}
function init_my_shifts() {
if (incoming_shifts !== null) {
init_incoming_shifts();
} else {
load_partner_shifts(partner_data.partner_id)
.then(init_incoming_shifts);
}
if (partner_history !== null) {
init_history();
} else {
load_partner_history()
.then(init_history);
}
/**
* if no incoming_services || no history {
* if no incoming : load incoming
* if no history : load hitstory
* } else {
* do the stuff
* }
*/
}
\ No newline at end of file
......@@ -4,7 +4,8 @@
var base_location = null,
current_location = null,
incoming_shifts = null;
incoming_shifts = null,
partner_history = null;
var date_options = {weekday: "long", year: "numeric", month: "long", day: "numeric"};
......@@ -15,7 +16,7 @@ var date_options = {weekday: "long", year: "numeric", month: "long", day: "numer
* @param {int} partner_id
*/
function load_partner_shifts(partner_id) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
$.ajax({
type: 'GET',
url: "/shifts/get_list_shift_partner/" + partner_id,
......@@ -34,7 +35,7 @@ function load_partner_shifts(partner_id) {
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'members-space.index');
report_JS_error(err, 'members_space.index');
closeModal();
// TODO Notify
......@@ -67,22 +68,22 @@ function update_dom() {
if (window.location.pathname === base_location || window.location.pathname === base_location + "home") {
current_location = "home";
$( "#main_content" ).load( "/members-space/homepage", update_content );
$( "#main_content" ).load( "/members_space/homepage", update_content );
$("#nav_home").addClass("active");
} else if (window.location.pathname === base_location + "mes-infos") {
current_location = "my_info";
$( "#main_content" ).load( "/members-space/my_info", update_content );
$( "#main_content" ).load( "/members_space/my_info", update_content );
$("#nav_my_info").addClass("active");
} else if (window.location.pathname === base_location + "mes-services") {
current_location = "my_shifts";
$( "#main_content" ).load( "/members-space/my_shifts", update_content );
$( "#main_content" ).load( "/members_space/my_shifts", update_content );
$("#nav_my_shifts").addClass("active");
} else if (window.location.pathname === base_location + "echange-de-services") {
current_location = "shifts_exchange";
$( "#main_content" ).load( "/members-space/shifts_exchange", update_content );
$( "#main_content" ).load( "/members_space/shifts_exchange", update_content );
$("#nav_shifts_exchange").addClass("active");
} else {
$( "#main_content" ).load( "/members-space/no_content" );
$( "#main_content" ).load( "/members_space/no_content" );
}
}
......@@ -97,20 +98,42 @@ function update_dom() {
case 'my_info':
init_my_info();
break;
case 'my_services':
case 'my_shifts':
init_my_shifts();
break;
case 'shifts_exchange':
init_my_shifts();
init_shifts_exchange();
break;
default:
console.log(`Bad input`);
}
}
/* - Shifts */
/**
* Prepare a shift line to insert into the DOM.
* Is used in: Home - My Shifts tile ; My Shifts - Incoming shifts section
*
* @param {String} date_begin beginning datetime of the shift
* @returns JQuery node object of the formatted template
*/
function prepare_shift_line_template(date_begin) {
let shift_line_template = $("#shift_line_template");
let datetime_shift_start = new Date(date_begin);
let f_date_shift_start = datetime_shift_start.toLocaleDateString("fr-fr", date_options);
f_date_shift_start = f_date_shift_start.charAt(0).toUpperCase() + f_date_shift_start.slice(1);
shift_line_template.find(".shift_line_date").text(f_date_shift_start);
shift_line_template.find(".shift_line_time").text(datetime_shift_start.toLocaleTimeString("fr-fr"));
return shift_line_template;
}
$(document).ready(function() {
$.ajaxSetup({ headers: { "X-CSRFToken": getCookie('csrftoken') } });
base_location = (app_env === 'dev') ? '/members-space/' : '/';
base_location = (app_env === 'dev') ? '/members_space/' : '/';
update_dom();
});
......@@ -10,5 +10,6 @@ urlpatterns = [
url(r'^my_shifts$', views.my_shifts),
url(r'^shifts_exchange$', views.shifts_exchange),
url(r'^no_content$', views.no_content),
url(r'^get_points_history$', views.get_points_history),
url('/*$', views.index),
]
......@@ -3,9 +3,10 @@ from outils.for_view_imports import *
from django.urls import reverse
from sales.models import CagetteSales
from outils.common import Verification
from members.models import CagetteMember
from shifts.models import CagetteShift
from members_space.models import CagetteMembersSpace
import hashlib
......@@ -28,7 +29,7 @@ def index(request, exception=None):
'title': 'Espace Membre',
'app_env': getattr(settings, 'APP_ENV', 'prod')
}
template = loader.get_template('members-space/index.html')
template = loader.get_template('members_space/index.html')
if ('failure' in credentials):
# Bad credentials (or none)
......@@ -102,36 +103,52 @@ def index(request, exception=None):
return _get_response_according_to_credentials(request, credentials, context, template)
def home(request):
template = loader.get_template('members-space/home.html')
template = loader.get_template('members_space/home.html')
context = {
'title': 'Espace Membres',
}
return HttpResponse(template.render(context, request))
def my_info(request):
template = loader.get_template('members-space/my_info.html')
template = loader.get_template('members_space/my_info.html')
context = {
'title': 'Mes Infos',
}
return HttpResponse(template.render(context, request))
def my_shifts(request):
template = loader.get_template('members-space/my_shifts.html')
template = loader.get_template('members_space/my_shifts.html')
context = {
'title': 'Mes Services',
}
return HttpResponse(template.render(context, request))
def shifts_exchange(request):
template = loader.get_template('members-space/shifts_exchange.html')
template = loader.get_template('members_space/shifts_exchange.html')
context = {
'title': 'Échange de Services',
}
return HttpResponse(template.render(context, request))
def no_content(request):
template = loader.get_template('members-space/no_content.html')
template = loader.get_template('members_space/no_content.html')
context = {
'title': 'Contenu non trouvé',
}
return HttpResponse(template.render(context, request))
\ No newline at end of file
return HttpResponse(template.render(context, request))
def get_points_history(request):
res = {}
partner_id = int(request.GET.get('partner_id'))
if 'verif_token' in request.GET and Verification.verif_token(request.GET.get('verif_token'), partner_id) is True:
m = CagetteMembersSpace()
limit = int(request.GET.get('limit'))
date_from = getattr(settings, 'START_DATE_FOR_POINTS_HISTORY', '2018-01-01')
res["data"] = m.get_points_history(partner_id, limit, date_from)
else:
return JsonResponse(res, status=403)
return JsonResponse(res)
\ No newline at end of file
......@@ -27,3 +27,6 @@ COMPANY_NAME = "Demo interfoodcoop"
SHOP_CATEGORIES = {}
EXCLUDE_SHOP_CATEGORIES = []
MIN_DELAY_FOR_SLOT = 4
# New members space
START_DATE_FOR_POINTS_HISTORY = "2018-01-01"
......@@ -333,6 +333,10 @@
- MEALS_PICKING_TYPE_ID = 10
### New members space
- START_DATE_FOR_POINTS_HISTORY = "2018-01-01"
......
......@@ -53,7 +53,7 @@ INSTALLED_APPS = (
'shop',
'shelfs',
'sales',
'members-space',
'members_space',
# 'tests'
)
......@@ -101,6 +101,7 @@ STATICFILES_DIRS = (
"shop/static",
"shelfs/static",
"orders/static",
"members_space/static",
# "tests/static"
)
......
......@@ -45,7 +45,7 @@ urlpatterns = [
url(r'^shop/', include('shop.urls')),
url(r'^shelfs/', include('shelfs.urls')),
url(r'^sales/', include('sales.urls')),
url(r'^members-space/', include('members-space.urls')),
url(r'^members_space/', include('members_space.urls')),
]
try:
......
......@@ -3,7 +3,7 @@
<h1>Mon espace membre</h1>
</div>
<div class="tiles_container">
<div class="tile" id="tile_my_info">
<div class="tile" id="home_tile_my_info">
<div class="tile_title">
Mes Infos
</div>
......@@ -11,7 +11,7 @@
À venir...
</div>
</div>
<div class="tile" id="tile_my_services">
<div class="tile" id="home_tile_my_services">
<div class="tile_title">
Mes Services
</div>
......@@ -22,11 +22,11 @@
</div>
<button type="button", class="btn btn--primary" id="home_go_to_shift_history">
Accéder à l'historique de mes services
Accéder à mon historique
</button>
</div>
</div>
<div class="tile" id="tile_services_exchange">
<div class="tile" id="home_tile_services_exchange">
<div class="tile_title">
Échange de services
</div>
......@@ -36,7 +36,7 @@
</button>
</div>
</div>
<div class="tile" id="tile_help">
<div class="tile" id="home_tile_help">
<div class="tile_title">
J'ai une demande
</div>
......
......@@ -3,6 +3,7 @@
{% block additionnal_css %}
<link rel="stylesheet" href="{% static "css/members-space.css" %}?v=">
<link rel="stylesheet" href="{% static "css/members-space-my-shifts.css" %}?v=">
{% endblock %}
{% block additionnal_scripts %}{% endblock %}
......@@ -10,7 +11,7 @@
{% block content %}
<div class="page_body">
{% include "members-space/header.html" %}
{% include "members_space/header.html" %}
<div id="main_content" class="page_content">
</div>
......@@ -22,6 +23,16 @@
<span class="shift_line_date"></span> - <span class="shift_line_time"></span>
</div>
</div>
<div id="history_line_template">
<div class="history_table_line">
<div class="table_line_el table_line_date"></div>
<div class="table_line_el table_line_created_by"></div>
<div class="table_line_el table_line_service"></div>
<div class="table_line_el table_line_desc"></div>
<div class="table_line_el table_line_pts"></div>
</div>
</div>
</div>
</div>
......
<div id="my_shifts">
<div class="page_title txtcenter">
<h1>Mes Services</h1>
</div>
<div class="tiles_container">
<div class="tile full_width_tile" id="incoming_services_area">
<div class="tile_title">
À venir
</div>
<div class="tile_content" id="incoming_services"></div>
</div>
<div class="tile full_width_tile" id="history_area">
<div class="tile_title">
Historique des mouvements de points
</div>
<div class="tile_content" id="history">
<div class="history_table">
<div class="history_table_header">
<div class="table_header_el table_header_date">
Date
</div>
<div class="table_header_el table_header_created_by">
Créé par
</div>
<div class="table_header_el table_header_service">
Service ??
</div>
<div class="table_header_el table_header_desc">
Description
</div>
<div class="table_header_el table_header_pts">
Mouvement de points
</div>
</div>
<div class="history_table_content">
</div>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment