Skip to content

Commit

Permalink
Achille/ticket7 - version 0.0.21 (#23)
Browse files Browse the repository at this point in the history
* Added colors in LastSeen table, and days count in the tooltip for ticket #7

* Changed period length for last seen

* draft of days since last seen

* Issue with triggering the searching in the table

* refactor + filtering done + ignoring weekends

Co-authored-by: Achille Bailly <a.bailly-stagiaire@adacis.net>
  • Loading branch information
AchilleBailly and Achille Bailly authored Nov 7, 2022
1 parent 048ddf0 commit 42dcd08
Show file tree
Hide file tree
Showing 15 changed files with 687 additions and 555 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Where am I ?</name>
<summary><![CDATA[Is a simple application to locate everybody in your company.]]></summary>
<description><![CDATA[Is a simple application to locate everybody in your company.]]></description>
<version>0.0.20</version>
<version>0.0.21</version>
<licence>agpl</licence>
<author mail="contact@adacis.net" homepage="https://www.adacis.net">ADACIS</author>
<namespace>Whereami</namespace>
Expand Down
2 changes: 1 addition & 1 deletion js/adminSection.app.js

Large diffs are not rendered by default.

47 changes: 40 additions & 7 deletions js/adminSection.app.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
/*!
* Sizzle CSS Selector Engine v2.3.6
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://js.foundation/
*
* Date: 2021-02-16
*/

/*!
* jQuery JavaScript Library v3.6.1
* https://jquery.com/
*
* Includes Sizzle.js
* https://sizzlejs.com/
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2022-08-26T17:52Z
*/

/*!
DataTables Bootstrap 3 integration
©2011-2015 SpryMedia Ltd - datatables.net/license
*/

/*! DataTables 1.12.1
* ©2008-2022 SpryMedia Ltd - datatables.net/license
*/

/*! FixedColumns 4.1.0
* 2019-2022 SpryMedia Ltd - datatables.net/license
*/

/*! FixedColumns 4.1.0
* 2019-2022 SpryMedia Ltd - datatables.net/license
*/
2 changes: 1 addition & 1 deletion js/main.app.js

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions js/main.app.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,3 @@
/*! FixedColumns 4.1.0
* 2019-2022 SpryMedia Ltd - datatables.net/license
*/

/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
2 changes: 1 addition & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PageController extends Controller
private $calendarManager;
private $myDb;
private $urlGenerator;
private $logger;
public $logger;

/**
*
Expand Down
43 changes: 26 additions & 17 deletions lib/MyClass/MyEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace OCA\Whereami\MyClass;

use OCA\Whereami\Db\Bdd;
use DateTimeImmutable;
use DateTime;
use Psr\Log\LoggerInterface;

class MyEvent
{
Expand All @@ -25,15 +23,20 @@ public function __construct(
) {
$this->myDb = $myDb;
$this->id = $e['id'];
$this->dtStart = $e["objects"][0]["DTSTART"][0]->format("Y-m-d");
$this->dtEnd = $e["objects"][0]["DTEND"][0]->format("Y-m-d");
$this->dtStart = $e["objects"][0]["DTSTART"][0]->modify('+ 1 minute')->format('Y-m-d H:i:s');
$this->dtEnd = $e["objects"][0]["DTEND"][0]->modify('- 1 minute')->format('Y-m-d H:i:s');
$this->nextcloud_users = $this->getNameCalendar($this->id);
$this->summary = str_replace("@", "", $e["objects"][0]["SUMMARY"][0]);
$this->place = $this->extractData(",", 0, $this->summary);

preg_match_all("/D[0-9]{5}/", $this->summary, $this->quote);
}

public function toString()
{
return "Event at " . $this->place . " by " . $this->nextcloud_users . " From " . $this->dtStart . " to " . $this->dtStart;
}

public function getNameCalendar($calendarsUid)
{
$res = $this->myDb->getCalendars($calendarsUid)[0]["principaluri"];
Expand Down Expand Up @@ -104,9 +107,9 @@ public function eventCross($event): bool
public function getSeen($e)
{
if ($this->dtEnd > $e->dtEnd) {
return (new DateTime($e->dtEnd))->modify('-1 day')->format("Y-m-d");
return (new DateTime($e->dtEnd))->format("Y-m-d");
} else {
return (new DateTime($this->dtEnd))->modify('-1 day')->format("Y-m-d");
return (new DateTime($this->dtEnd))->format("Y-m-d");
}
}

Expand All @@ -123,18 +126,24 @@ public function parseListEvents($events, $listSeen): array
$user != $thisUser // Je ne me teste pas moi même
&& strtoupper($e->place) === strtoupper($this->place) // On est sur le même lieu
&& $this->eventCross($e) // Nos dates sont dans le même interval
&&
(
(isset($listSeen[$user]['seen']) && $listSeen[$user]['seen'] < $this->getSeen($e)) // J'ai déjà enregistré pour cet utilisateur
||
(!array_key_exists($user, $listSeen)) // Pas d'informatin précédente sur cet utilisateur
)
) {
$listSeen[$user] = [
'load' => False,
'place' => $e->place,
'seen' => $this->getSeen($e),
];
if (array_key_exists($user, $listSeen) && $listSeen[$user]['seen'] < $this->getSeen($e)) { // La date enregistrée est plus ancienne, on l'update
$listSeen[$user] = [
'load' => False,
'place' => $e->place,
'seen' => $this->getSeen($e),
'count' => $listSeen[$user]['count'] + 1
];
} else if (array_key_exists($user, $listSeen)) { // La date enregistrée est plus récente, on incrémente le compteur tout de même
$listSeen[$user]['count'] = $listSeen[$user]['count'] + 1;
} else { // nouvel event, on l'ajoute
$listSeen[$user] = [
'load' => False,
'place' => $e->place,
'seen' => $this->getSeen($e),
'count' => 1
];
}
}
}
return $listSeen; // Retour
Expand Down
4 changes: 4 additions & 0 deletions src/js/admin/adminSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ var optsIconsToPerson = {
closeIconClass: 'closeIcon'
}


/**
* Initializes with the values stored in DB
*/
function initDbIcons() {
var data = getAllIcons().onload();
var groupedLabel = groupBy(data, 'label');
Expand Down
8 changes: 5 additions & 3 deletions src/js/class/ListEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export class ListEvents {
}
})

if (!found && (days[from.getDay()] === 'sunday' || days[from.getDay()] === 'saturday')) {
if (days[from.getDay()] === 'sunday' || days[from.getDay()] === 'saturday') {
myCell.setAttribute('style', 'background-color: var(--color-box-shadow);')
res = ''
} else if (!found) {
myCell.setAttribute('style', 'background-color: yellow; color: #222;')
res += 'shame'
Expand Down Expand Up @@ -71,8 +72,9 @@ export class ListEvents {
if (e.inInterval(from)) {
let userTetra = Events.compute_tetragraph(e.nextcloud_users)
res += 1
if (placeIsExcluded)
if (placeIsExcluded) {
isSomeoneThere = true
}

else if (groupedIcons[userTetra])
for (let dic of groupedIcons[userTetra]) {
Expand All @@ -92,7 +94,7 @@ export class ListEvents {
if (!isSomeoneThere)
myCell.style = "background-color: red; text-align: center;"

if (!found && (days[from.getDay()] === 'sunday' || days[from.getDay()] === 'saturday')) {
if (days[from.getDay()] === 'sunday' || days[from.getDay()] === 'saturday') {
myCell.setAttribute('style', 'text-align: center; background-color: var(--color-box-shadow);')
myCell.innerText = ''
} else if (!found) {
Expand Down
70 changes: 47 additions & 23 deletions src/js/index/main.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,71 @@
import { getData, lastSeen, optionDatatable } from '../module/xhr'
import { translate as t } from '@nextcloud/l10n'
import DataTable from 'datatables.net-bs/js/dataTables.bootstrap.min.js'
import { getData, lastSeen } from '../module/xhr'
import { getLoader } from '../module/datatables'
import 'datatables.net-fixedcolumns/js/dataTables.fixedColumns'
import 'datatables.net-bs/css/dataTables.bootstrap.min.css'

function setDateLastSeen() {
const toDay = new Date()
toDay.setDate(toDay.getDate() + 1)
document.getElementById('dtEnd').valueAsDate = toDay
toDay.setDate(toDay.getDate() - 35)
document.getElementById('dtStart').valueAsDate = toDay
}

function setDateUsual() {
const toDay = new Date()
if (document.getElementById('seen') !== null) {
document.getElementById('dtStart').valueAsDate = toDay
toDay.setDate(toDay.getDate() + 14)
document.getElementById('dtEnd').valueAsDate = toDay
}
}


/**
* Set the input fields for the dates to disabled or not
* @param {Boolean} bool
*/
function setDateDisabled(bool) {
if (bool) {
document.getElementById('dtStart').setAttribute('disabled', bool.toString());
document.getElementById('dtEnd').setAttribute('disabled', bool.toString());
}
else {
document.getElementById('dtStart').removeAttribute('disabled')
document.getElementById('dtEnd').removeAttribute('disabled')
}
}


window.addEventListener('click', e => {

if (e.target.className.includes('showbyemployees')) {
setDateUsual()
setDateDisabled(false)
document.getElementById('myapp').innerHTML = ''
document.getElementById('myapp').appendChild(getLoader())
getData(document.getElementById('dtStart').value, document.getElementById('dtEnd').value, DataTable, 'nextcloud_users')
getData(document.getElementById('dtStart').value, document.getElementById('dtEnd').value, 'nextcloud_users')
}
else if (e.target.className.includes('showbylocation')) {
setDateUsual()
setDateDisabled(false)
document.getElementById('myapp').innerHTML = ''
document.getElementById('myapp').appendChild(getLoader())
getData(document.getElementById('dtStart').value, document.getElementById('dtEnd').value, DataTable, 'summary')
getData(document.getElementById('dtStart').value, document.getElementById('dtEnd').value, 'summary')
}
else if (e.target.className.includes('showbyquote')) {
setDateUsual()
setDateDisabled(false)
document.getElementById('myapp').innerHTML = ''
document.getElementById('myapp').appendChild(getLoader())
getData(document.getElementById('dtStart').value, document.getElementById('dtEnd').value, DataTable, 'summary')
getData(document.getElementById('dtStart').value, document.getElementById('dtEnd').value, 'summary')
}
else if (e.target.className.includes('lastSeen')) {
setDateLastSeen()
setDateDisabled(true)
document.getElementById('myapp').innerHTML = ''
document.getElementById('myapp').appendChild(getLoader())
lastSeen(document.getElementById('dtStart').value, document.getElementById('dtEnd').value, DataTable)
lastSeen(document.getElementById('dtStart').value, document.getElementById('dtEnd').value)
}
else if (e.target.className.includes('helper')) {
document.getElementById('helper').style.display = 'block'
Expand All @@ -36,10 +75,6 @@ window.addEventListener('click', e => {
})

window.addEventListener('DOMContentLoaded', function () {
// if page containing 'dtstart' not loaded
// if (document.getElementById('dtStart') === null) {
// return;
// }
const toDay = new Date()
document.getElementById('dtStart').valueAsDate = toDay
toDay.setDate(toDay.getDate() + 14)
Expand All @@ -48,19 +83,8 @@ window.addEventListener('DOMContentLoaded', function () {
document.getElementById('myapp').appendChild(getLoader())
getData(document.getElementById('dtStart').value,
document.getElementById('dtEnd').value,
DataTable,
'nextcloud_users'
)
})

/**
*
* @returns
*/
function getLoader() {
const center = document.createElement('center')
const divLoader = document.createElement('div')
divLoader.setAttribute('class', 'lds-dual-ring')
center.appendChild(divLoader)
return center
}

Loading

0 comments on commit 42dcd08

Please sign in to comment.