Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 0.0.37 #44

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 200 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,203 @@
[![Deploy app](https://github.com/Adacis/whereami/actions/workflows/release.yml/badge.svg)](https://github.com/Adacis/whereami/actions/workflows/release.yml)

# whereami
Is a simple application to locate everybody in your company
# Where Am I ?

<div align="center">
<a href="
https://github.com/LoueTaVoiture/louetavoiture-front/">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Nextcloud_Logo.svg/2560px-Nextcloud_Logo.svg.png" alt="Logo" width="130">
<img src="https://github.com/Adacis/whereami/blob/main/img/app-dark.svg" alt="Logo dark" width="120" height="130">
</a>

<h3 align="center">Where Am I ? (WAI)</h3>

<p align="center">
Where am I is a management application allowing users to record and see who and what everyone is working on in a calendar and table. The application is hosted on Nextcloud.
<br />
<br />
</p>
</div>


## Tech Stack

**Client:** JS

**Server:** PHP Symphony

**Database:** MySQL

## Installation

### Prerequisites

The Git command must be installed on the machine, or if you're on Windows or MacOS, you can use the Github Desktop application: https://desktop.github.com/

Once git is installed on your machine, clone the WhereAmI project (https://github.com/Adacis/whereami.git) to a directory on your machine.

Install Docker (Windows, MacOS or Linux): https://www.docker.com/products/docker-desktop
or from the command line (e.g. Ubuntu):
https://docs.docker.com/engine/install/ubuntu/

After installing Docker, create the “nextcloud” network:
```sh
docker network create nextcloud
```



### Installing the Nextcloud database

This part of the installation will enable us to install a MySQL 8.3.0 database, which will be the database for our Nextcloud application.

**Step 1**:
Go to the directory where the project was cloned in the prerequisites and then to the “whereami-docker” folder:

```sh
cd whereami-docker/
```

**Step 2**:
Run the docker command to create the MySQL database container:
```sh
docker compose up -d
```

**Step 3**:
Check that the container has launched with the command :
```sh
docker ps
```

A container named “nextcloud-db” should be present in the list. If not, you can retrieve the container's logs with the command
docker logs nextcloud-db

**Step 4**:
Check that the database is accessible with a tool like Dbeaver (https://dbeaver.io/).
The identifiers are as follows:
```
Server Host: localhost
Port: 3306
Username: nextcloud
Password: nextcloud
```

### Installing the Nextcloud application

This part requires you to have installed the database beforehand.

**Step 1**:
Create a “nextcloud_data” folder on your machine:
```sh
mkdir /Users/miage/Documents/nextcloud_data
```

**Step 2**:
Launch the nextcloud container, which loads the nextcloud:28.0.5 image.
(Remember to change the data folder /Users/miage/Documents/nextcloud_data to the one you created in step 1)
```sh
docker run -d --name nextcloud -p 8001:80 -v /Users/miage/Documents/nextcloud_data:/var/www/html --network nextcloud nextcloud:28.0.5
```

Note that the container will be on port 8001 of the machine, so it's possible to modify it if necessary.

**Step 3**:
Check that the container has launched with the command :
```sh
docker ps
```

A container named “nextcloud” should be present in the list. If not, you can retrieve the container's logs with the command :
```sh
docker logs nextcloud
```


**Step 4**:
Go to Nextcloud at http://localhost:8001
Enter the credentials for the Nextcloud administrator account you want, e.g. :
```
Username : adacis
Password : admin
```

In the “Configure database” section, select the “MySQL/MariaDB” box and enter the following information:
```
Database user: nextcloud
Database password: nextcloud
Database name: nextcloud-db
Database host: nextcloud-db:3306
```



Then click on Install.
You now have an instance of Nextcloud 28.0.5.

### Installing the WhereAmI application

**Step 1** :
Take the project already cloned in a directory, and copy it into the nextcloud_data/apps/ folder created during Nextcloud installation with the command
```sh
cp -r [Directory containing cloned project]/whereami [Path to nextcloud_data folder]/nextcloud_data/apps/
```

**Step 2** :
- Log on to Nextcloud with an administrator account
- Click on your profile photo in the top right-hand corner of the screen
- Select “Applications
- Search for the “Where am I?” application and click on Activate


You now have the Where Am I application on Nextcloud. To use this application, please refer to the user manual.


## Deployment (only in dev mode)

### First time deployment
To deploy this project run the following commands in the order :
- Start the Docker Bash Terminal for Nextcloud
```bash
docker exec -it nextcloud bash
```
- Navigate to the correct folder
```bash
cd apps/whereami/
```
- Install and update NPM if you don't have it
```bash
apt-get update && apt-get install -y npm
```
- Initialise the project
```bash
make npm-init
```
- Build the project
```bash
make build-js
```

### Build
- Start the Docker Bash Terminal
```bash
docker exec -it nextcloud bash
```
- Place yourself in the correct folder
```bash
cd apps/whereami/
```
- Build the project
```bash
make build-js
```
## Features
- **Event Assignment using the Calendar feature**: Users can register themselves, record their whereabouts and time slots for specific contracts as well as their work status, which are then converted into full or half work days.
- **Employees Tab**: A summary table of all users, their locations, and their status for the selected date range.
- **Location Tab**: A summary table showing the number of users by location for the selected date range.
- **Last Seen Tab**: A summary table of all the instances where users have crossed paths with other users within the selected date range.
- **Contract Tab**: A summary table listing all users with their contracts and the total hours worked, rounded to the nearest half day, for the selected date range.
- **Summary Tab**: A summary table showing the locations and the time spent at each location by the user for the selected month.
- **Hover Summary Functionality**: Provide brief information when hovering over specific dates.

## Authors
- [@Benjamin Aimard](https://github.com/baimard)
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<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.36</version>
<version>0.0.37</version>
<licence>agpl</licence>
<author mail="contact@adacis.net" homepage="https://www.adacis.net">ADACIS</author>
<namespace>Whereami</namespace>
<category>office</category>
<category>organization</category>
<bugs>https://github.com/Adacis/whereami/issues</bugs>
<dependencies>
<nextcloud min-version="29" max-version="29"/>
<nextcloud min-version="28" max-version="29"/>
</dependencies>
<settings>
<admin>OCA\Whereami\Settings\WhereamiAdmin</admin>
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getNavigationLink()
public function getContracts(String $dtStart, String $dtEnd)
{
// Fetch data from the database
$result = $this->myDb->getContracts($dtStart, $dtEnd);
$result = $this->myDb->getContracts($dtStart, $dtEnd, $this->userId);

// Initialize arrays to store contracts and users per contract
$contracts = [];
Expand Down
43 changes: 40 additions & 3 deletions lib/Db/Bdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,29 @@ class Bdd
private String $tableprefix;
private $logger;

private $grpWhereAmI = 'whereami_global';


public function __construct(IDbConnection $db, LoggerInterface $log)
{
$this->pdo = $db;
$this->tableprefix = '*PREFIX*' . "whereami_";
$this->logger = $log;
$this->initializeGroupWhereAmI();
}

/**
* Insert the group whereami_global in the database if it does not exist
*/
public function initializeGroupWhereAmI()
{

$sql = "SELECT * FROM `*PREFIX*groups` WHERE `gId` = ?";

if (empty($this->execSQLNoJsonReturn($sql, array($this->grpWhereAmI)))) {
$sql = "INSERT INTO `*PREFIX*groups` (`gId`,`displayname`) VALUES (?,?)";
$this->execSQLNoData($sql, array($this->grpWhereAmI, $this->grpWhereAmI));
}
}

public function listUID()
Expand Down Expand Up @@ -180,14 +198,21 @@ public function getIconsInPrefixList($person, $label)
* Retrieve activity reports for contracts within a specified date range.
*
* This method fetches activity reports including the number of contracts (`nb_contract`),
* associated usernames (`username`), aggregated activity values (`activity_report_value`),
* associated usernames (`uid`), aggregated activity values (`activity_report_value`),
* and corresponding dates (`activity_report_date`) for a given time period.
* The results are filtered based on the user's group membership. If the user belongs
* to the "WhereAmI" global group, they will see all available data for every user. Otherwise,
* they will only see their own data.
*
* @see Bdd::$grpWhereAmI Constant that holds the value for the "WhereAmI" global group.
* @param string $dtStart The start date of the date range (YYYY-MM-DD format).
* @param string $dtEnd The end date of the date range (YYYY-MM-DD format).
* @param string $uid The ID of the current user.
* @return array Fetched database results containing activity report details.
*/
public function getContracts($dtStart, $dtEnd){
public function getContracts($dtStart, $dtEnd, $uid){
$isGlobalUser = $this->isGrpWanted($uid, $this->grpWhereAmI);

$sql = "SELECT
REGEXP_SUBSTR(value, '\\\\b[Dd]\\\\d{5}\\\\b') as nb_contract,
uid,
Expand Down Expand Up @@ -221,9 +246,11 @@ public function getContracts($dtStart, $dtEnd){
AND FROM_UNIXTIME(oc.firstoccurence) BETWEEN ? AND ?
AND oc.deleted_at IS NULL
) sr
WHERE
(? = TRUE) OR ? = uid
GROUP BY
value, uid, first_occurence, last_occurence";
return $this->execSQLNoJsonReturn($sql, array($dtStart, $dtEnd));
return $this->execSQLNoJsonReturn($sql, array($dtStart, $dtEnd, $isGlobalUser, $uid));
}


Expand All @@ -249,6 +276,16 @@ private function getQuadri($name)
return strtoupper($quadri);
}

/**
* Return true if the user is in the group wanted
* @userId : current user id
*/
public function isGrpWanted($userId,$grp)
{
$sql = "SELECT * FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` = ?";
return !empty($this->execSQLNoJsonReturn($sql, array($grp, $userId)));
}

/**
* @sql
* @array() //prepare statement
Expand Down
13 changes: 3 additions & 10 deletions src/js/class/ListEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class ListEvents {
e.place2 = e.place
}


if (placeIsExcluded) {
isSomeoneThere = true
isSomeoneThere2 = true
Expand All @@ -118,16 +119,10 @@ export class ListEvents {
}
}

if (e.place === this.id) {
title += e.nextcloud_users + '\n'
res += 1
found = true
}
if (e.place2 === this.id) {
title2 += e.nextcloud_users + '\n'
res2 += 1
found2 = true
}

}
})

Expand All @@ -140,10 +135,8 @@ export class ListEvents {
let div1 = this.createDiv(res, title, found, isSomeoneThere, from)
div.appendChild(div1)
if (title !== title2) {
let div2 = this.createDiv(res2, title2, found2, isSomeoneThere2, from)
div1.classList.add('cell-base-two')
div2.classList.add('cell-base-two')
div.appendChild(div2)
div.appendChild(div1)
}
else
div1.classList.add('cell-base-alone')
Expand Down
Loading