Skip to content

Commit

Permalink
nouvelle version cf. changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane committed Jun 8, 2023
1 parent 6d92f56 commit c4b553b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

LEGENDE: C: Corrections(Fixes) / B: Corrections de Bug (BugFixes) / F: Ajout de fonctionnalité (Features) / D: Divers (Misc)

## 1.10.0015 (08/06/2023)
- C: Prise en compte d'une modification d'une librairie utilisée dans l'application (GM_Config) qui a évolué et impacte la récuperation des données de configuration,
certaines options mineures comme la configuration de fichier css personnalisés sont non utilisées désormais (mais pas non activées).

## 1.10.0014 (09/08/2022)
- C: Prise en compte des évolutions d'interface utilisateur openclassrooms
- B: Correction d'un bug en supprsseion d'historique (bookmarks) quand on ne donnait pas de date pour filtrer les élements
Expand Down
22 changes: 14 additions & 8 deletions src/gmc.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const windowcss = '#OCAddonsCfg {background-color: lightblue;} #OCAddonsCfg .reset_holder {float: left; position: relative; bottom: -1em;} #OCAddonsCfg .saveclose_buttons {margin: .7em;}';
const iframecss = 'height: 16.7em; width: 30em; border: 1px solid; border-radius: 3px; position: fixed; z-index: 999;';
const dbgcss = 'position: absolute;top: 5px; left: 5px; right: 5px; bottom: 5px;padding: 10px;overflow-y: auto;display: none;background: rgba(250, 250, 250, 0.3);border: 3px solid #888;font: 14px Consolas,Monaco,Monospace;color: #ddd;z-index: 500';


const appmenu = {
id: 'OCAddonsCfg',
title: 'Configuration du module',
Expand Down Expand Up @@ -66,7 +68,7 @@ const appmenu = {
type: 'input',
default: 120000,
},

checksessionalreadyexists: {
section: ['Application', 'Base de donnée'],
label: 'sessions: vérifier existence avant insertion',
Expand All @@ -82,14 +84,14 @@ const appmenu = {
type: 'input',
default: '1em;',
},

use_custom_css: {
label: 'utiliser des styles personnalisés',
labelPos: 'left',
type: 'checkbox',
default: false,
},

custom_css_url: {
label: 'url de la feuille de style (si plusieurs les séparer par des virgules)',
labelPos: 'left',
Expand Down Expand Up @@ -118,7 +120,7 @@ const appmenu = {
labelPos: 'left',
type: 'checkbox',
default: true,
},*/
},*/
'hackheaderzindex':{
section: ['', 'Hack'],
label: 'Changer le zindex du bandeau haut',
Expand Down Expand Up @@ -152,6 +154,10 @@ const appmenu = {
css: windowcss,
events:
{
'init': () => {
// initialization complete
// value is now available
},
save: function() {
GM_config.close();
}
Expand All @@ -164,9 +170,9 @@ var opencfg = function()
GM_config.open();
OCAddonsCfg.style = iframecss;
}
export {


export {
appmenu,
opencfg,
};
};
30 changes: 28 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,31 @@ const Facturier = {
function(){document.querySelector(".panel.draggable").scrollIntoView()});
//GM_registerMenuCommand('force - cbox', Facturier._forceCbox);
/* hacks */

// cf https://github.com/sizzlemctwizzle/GM_config/wiki/Asynchronous-read-and-write-migration
// Promise resolves when initialization completes
let onInit = config => new Promise(resolve => {
let isInit = () => setTimeout(() =>
config.isInit ? resolve() : isInit(), 0);
isInit();
});

// Generate a Promise
let init = onInit(appmenu);

// Break up get() calls
init.then(() => {
// initialization complete
// value is now available
if (GM_config.get("hackheaderzindex") === true) {
document.getElementById("header").style.zIndex = 0;
}
});

/*
if(GM_config.get('hackheaderzindex') === true){
document.getElementById('header').style.zIndex = 0; // because z index is 1000 in oc rules
}
}*/
/* set size of content */
//GM_addStyle('.swal2-content{font-size:'+GM_config.get('sizeofcontentlist')+'}');
GM_addStyle('.swal2-title{font-size:1.275em}'); // set by default to 1.875em by CSS of SWAL
Expand Down Expand Up @@ -1038,8 +1060,12 @@ if(STT_VERSION) {
}
);

// NOTESTT Ajout Juin2023 pour gérer un changement de la librairie GM_config
// je suis obligé de désactiver cette option car tout le code doit changer
let FacturierMonkeyCfg_use_custom_css = false

if (GM_config.get("use_custom_css") === true) {
//if (GM_config.get("use_custom_css") === true) {
if ( FacturierMonkeyCfg_use_custom_css === true ) {
let sDependencies = GM_config.get("custom_css_url");
/*
fetchInject(['https://raw.githubusercontent.com/brettz9/load-stylesheets/master/dist/index-umd.min.js'])
Expand Down
82 changes: 62 additions & 20 deletions src/students_history.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* used by students to store history of students life
*
*
* a student history is a data with time of change, a type of data and an old value
*
*
* Example debug
*
*
* d_StudentHistory.addFunding('7582346',"financé par un tiers","20200801") Ajoute à MAAIKE un changement de financement ancienne valeur 1 avant le 01.08.2020
* d_StudentHistory.addFunding('7582346',"auto-financé","20200630") Ajoute à MAAIKE un changement de financement ancienne valeur 3 avant le 30.06.2020
* d_StudentHistory.find('7582346',d_StudentHistory.getType('FUNDING'),"20200901") doit rien sortir
* d_StudentHistory.find('7582346',d_StudentHistory.getType('FUNDING'),"20200701") doit sortir 1 la valeur avant le 01.08 mais pas 3 qui est une valeur plus ancienne encore
*
*
*/

/**
* date: timestamp, type: integer, id: string, value: mixed
**/
**/

import {
APP_DEBUG_STYLE, APP_WARN_STYLE, APP_ERROR_STYLE,
Expand All @@ -26,25 +26,25 @@ import {assert} from './utils.js';
* Factory function
*/
var fStudentHistory = function(){

const TBL_NAME = 'students_history';


// https://codeforwin.org/2018/05/10-cool-bitwise-operator-hacks-and-tricks.html paragraph 4.
const TYPE_FUNDING = 1;
const TYPE_PATH = 2;

/*
* return the type by giving
*/

const getType = function(sType){
if(sType.toUpperCase() === 'FUNDING') return TYPE_FUNDING;
if(sType.toUpperCase() === 'PATH') return TYPE_PATH;
throw Error('Erreur qui ne devrait jamais arriver en getype');
return false;
}

const addFunding = function(sStudentId, data, created=null){
return add(sStudentId, TYPE_FUNDING ,data, created);
};
Expand All @@ -59,13 +59,13 @@ var fStudentHistory = function(){
if (typeof sStudentId === 'number'){
sStudentId = sStudentId.toString(10)
}

assert(
typeof sStudentId === 'string',
'You must provide a string.',
TypeError
);
const db=App.Cfg.dbase;
const db=App.Cfg.dbase;
//if (typeof created === 'string'){ dtFrom = dayjs(created).format('YYYY-MM-DDTHH:mm:ssZZ')}
if (typeof created === 'string'){ created = dayjs(created); }
if(created === null){
Expand All @@ -86,7 +86,7 @@ var fStudentHistory = function(){
};
// delete all = d_dbase.get('students_history').remove().write();
const remove = function(sStudentId, iType=null, dtFrom=null){
const db=App.Cfg.dbase;
const db=App.Cfg.dbase;
if (sStudentId == null && iType == null && dtFrom == null){
console.log(`%cRemove all in student history`,APP_DEBUG_STYLE);
return db.get(TBL_NAME).remove().write();
Expand All @@ -107,9 +107,9 @@ var fStudentHistory = function(){
return db.get(TBL_NAME).remove( {id:sStudentId, type:iType, date:dtFrom.valueOf()} ).write();
//return db.get(TBL_NAME).remove( {id: _r.id} ).write();
};

/* get Data for a specified type before a specified date */

const find = function(sStudentId, iType, dtFrom=null){
const bDebug = false;
const db=App.Cfg.dbase;
Expand Down Expand Up @@ -149,12 +149,54 @@ var fStudentHistory = function(){
const min = arr => Math.min(...arr); // clone de la fonction min qui prend désormais en charge un array et plus une liste
let _needle = _iBaseDay + min(_r);
return db.get(TBL_NAME).filter(o => o.id === sStudentId && (o.type & iType) && o.date == _needle).value()[0];
};

/* modifie un element d'historique
* NOTESTT 20220911 non testé en plus je m'aperçois que la recherche n'est pas des plus efficaces puisque je ne peux pas chercher une valeur
* le plus simple reste encore de supprimer et recrée l'évenement
*/

const modify_value = function(sStudentId, iType, dtOfEvent=null, data){
const bDebug = false;
let _r;
_r = find(sStudentId, iType, dtOfEvent);
if (typeof _r === 'undefined'){
if(bDebug===true) console.log(`%cAs we find nothing there is nothing to modfiy`, APP_DEBUG_STYLE);
return undefined;
}


const db=App.Cfg.dbase;
//if (typeof created === 'string'){ dtFrom = dayjs(created).format('YYYY-MM-DDTHH:mm:ssZZ')}
if (typeof dtOfEvent === 'string'){ dtOfEvent = dayjs(dtOfEvent); }
if(dtOfEvent === null){
//dtOfEvent = dayjs().format('YYYY-MM-DDTHH:mm:ssZZ'); // FORMAT ISO 8601 for testing d_dayjs(d_dayjs().format('YYYY-MM-DDTHH:mm:ssZZ')) create date at today
// https://www.ionos.fr/digitalguide/sites-internet/developpement-web/iso-8601/
dtOfEvent = dayjs(); //prefer to timestamp
}
assert(
dtOfEvent instanceof dayjs,
'created date must be a string, a dayjs instance or null.',
TypeError
);

if(bDebug===true)console.log(`%cModify student history at date ${dayjs(dtOfEvent).format("YYYY-MM-DDTHH:mm:ssZZ")} data ${data} with type:${iType} cf const of object`,APP_DEBUG_STYLE);
db.get(TBL_NAME).find({id:_r.id}).assign({value:data}).write(); // update database

}

/*
*
*
*/

const modify_date = function(sStudentId, iType, dtOfEvent=null, data){
}

const isFunding = function(data){
return is(data, TYPE_FUNDING);
}

const isPath = function(data){
return is(data, TYPE_PATH);
}
Expand All @@ -173,7 +215,7 @@ var fStudentHistory = function(){
isPath,
tbl_name: TBL_NAME,
});

}

const StudentHistory = fStudentHistory();
Expand Down

0 comments on commit c4b553b

Please sign in to comment.