diff --git a/www/.env b/www/.env new file mode 100644 index 0000000..dbb8dad --- /dev/null +++ b/www/.env @@ -0,0 +1,33 @@ +# In all environments, the following files are loaded if they exist, +# the latter taking precedence over the former: +# +# * .env contains default values for the environment variables needed by the app +# * .env.local uncommitted file with local overrides +# * .env.$APP_ENV committed environment-specific defaults +# * .env.$APP_ENV.local uncommitted environment-specific overrides +# +# Real environment variables win over .env files. +# +# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. +# https://symfony.com/doc/current/configuration/secrets.html +# +# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). +# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration + +###> symfony/framework-bundle ### +APP_ENV=dev +APP_SECRET=8bd3643031a08d0cd34e6fd3f680fb22 +###< symfony/framework-bundle ### + +###> doctrine/doctrine-bundle ### +# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url +# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml +# +# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" +# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8&charset=utf8mb4" +DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=14&charset=utf8" +###< doctrine/doctrine-bundle ### + +### records folder +RECORDS_DIR=%kernel.project_dir%/../var/chunks # adapt to your needs +### diff --git a/www/.gitignore b/www/.gitignore index 7fdcc07..f6bc5ec 100644 --- a/www/.gitignore +++ b/www/.gitignore @@ -1,5 +1,6 @@ ###> symfony/framework-bundle ### +!.env /.env.local /.env.local.php /.env.*.local diff --git a/www/assets/app.js b/www/assets/app.js index ef1cc96..c3fd8fa 100644 --- a/www/assets/app.js +++ b/www/assets/app.js @@ -12,9 +12,13 @@ import './styles/menu.css'; // start the Stimulus application import './bootstrap'; -import './utils/spectro'; -import './utils/date'; +import feather from 'feather-icons'; +feather.replace(); -document.getElementsByClassName('prevent').map( - (e) => e.addEventListener('click', (e) => e.preventDefault()) -); \ No newline at end of file +try { + document.getElementsByClassName('prevent').map( + (e) => e.addEventListener('click', (e) => e.preventDefault()) + ); +} catch { + console.debug('no prevent class found'); +} diff --git a/www/assets/controllers/record.js b/www/assets/controllers/record.js new file mode 100644 index 0000000..55782be --- /dev/null +++ b/www/assets/controllers/record.js @@ -0,0 +1,7 @@ +(function() { + try { + let delete_buttons = document.getElementsByClassName("delete-button"); + } catch { + console.debug("no delete buttons found"); + } +})(); \ No newline at end of file diff --git a/www/assets/styles/app.css b/www/assets/styles/app.css index 332d54b..a9aa650 100644 --- a/www/assets/styles/app.css +++ b/www/assets/styles/app.css @@ -164,6 +164,12 @@ footer a:hover { font-style: italic; } +li, td { + align-items: center; +} + +td + /* .dropdown-button:hover { background-color: #900; color: white diff --git a/www/assets/utils/date.js b/www/assets/utils/date.js index bbef40f..9e74e51 100644 --- a/www/assets/utils/date.js +++ b/www/assets/utils/date.js @@ -1,7 +1,17 @@ +let date_input; +let endpoint; -let date_input = document.querySelector("input[type='date']"); -let next_date_button = document.getElementsByClassName("next-date-button")[0]; -let previous_date_button = document.getElementsByClassName("previous-date-button")[0]; +try { + date_input = document.querySelector(".date-selector input[type='date']"); + let next_date_button = document.getElementsByClassName("next-date-button")[0]; + let previous_date_button = document.getElementsByClassName("previous-date-button")[0]; + endpoint = document.querySelector(".date-selector a").href.split("/")[3]; + + next_date_button.addEventListener("click", next_date); + previous_date_button.addEventListener("click", previous_date); +} catch { + console.debug("no date input found"); +} function next_date() { let date = new Date(date_input.value); @@ -20,8 +30,5 @@ function previous_date() { function update_date_link() { let date = new Date(date_input.value); let date_link = document.querySelector(".date-selector a"); - date_link.href = `/today/${date.toISOString().split('T')[0]}/species`; + date_link.href = `/${endpoint}/${date.toISOString().split('T')[0]}/`; } - -next_date_button.addEventListener("click", next_date); -previous_date_button.addEventListener("click", previous_date); \ No newline at end of file diff --git a/www/assets/utils/spectro.js b/www/assets/utils/spectro.js index 9f19f6e..6785240 100644 --- a/www/assets/utils/spectro.js +++ b/www/assets/utils/spectro.js @@ -15,7 +15,7 @@ try { initialize(); }) } catch { - console.log("spectro not found"); + console.debug("spectro not found"); } function initialize() { diff --git a/www/config/services.yaml b/www/config/services.yaml index 2d6a76f..a0274a3 100644 --- a/www/config/services.yaml +++ b/www/config/services.yaml @@ -4,6 +4,7 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: + app.records_dir: '%env(resolve:RECORDS_DIR)%' services: # default configuration for services in *this* file diff --git a/www/package.json b/www/package.json index 058d070..e1d0e23 100644 --- a/www/package.json +++ b/www/package.json @@ -14,5 +14,8 @@ "dev": "encore dev", "watch": "encore dev --watch", "build": "encore production --progress" + }, + "dependencies": { + "feather-icons": "^4.29.0" } } diff --git a/www/src/Controller/RecordsController.php b/www/src/Controller/RecordsController.php new file mode 100644 index 0000000..f7021a8 --- /dev/null +++ b/www/src/Controller/RecordsController.php @@ -0,0 +1,74 @@ +list_records(); + $records = $this->only_on($date, $records); + return $this->render('records/index.html.twig', [ + 'records' => $records, + 'date' => $date, + ]); + } + + /** + * @Route("/records/remove/{basename}", name="record_remove") + */ + public function remove_record($basename) + { + $this->remove_record_by_basename($basename); + return $this->redirectToRoute('records_index'); + } + + private function list_records() + { + $records_path = $this->getParameter('app.records_dir')."/out/*.wav"; + $records = glob($records_path); + $records = array_map(function($record) { + $record = basename($record); + return $record; + }, $records); + return $records; + } + + private function get_record_date($record_path) + { + $record_basename = basename($record_path); + $record_date = explode("_", explode(".", $record_basename)[0])[1]; + $year = substr($record_date, 0, 4); + $month = substr($record_date, 4, 2); + $day = substr($record_date, 6, 2); + $date = "$year-$month-$day"; + return $date; + } + + private function only_on($date, $records) { + $filtered_records = array_filter($records, function($record) use ($date) { + return $this->get_record_date($record) == $date; + }); + return $filtered_records; + } + + private function remove_record_by_basename($basename) { + $record_path = $this->getParameter('app.records_dir')."/out/$basename"; + unlink($record_path); + unlink($record_path.".d/model.out.csv"); + rmdir($this->getParameter('app.records_dir')."/out/$basename.d"); + } +} \ No newline at end of file diff --git a/www/src/Controller/TodayController.php b/www/src/Controller/TodayController.php index b917094..2d1167f 100644 --- a/www/src/Controller/TodayController.php +++ b/www/src/Controller/TodayController.php @@ -119,7 +119,8 @@ class TodayController extends AbstractController $stat = $result->fetchAllAssociative(); $sql = "SELECT * FROM `observation` WHERE `taxon_id` = :id - AND strftime('%Y-%m-%d', `observation`.`date`) = :date"; + AND strftime('%Y-%m-%d', `observation`.`date`) = :date + ORDER BY `observation`.`date` ASC"; $stmt = $this->connection->prepare($sql); $stmt->bindValue(':id', $id); $stmt->bindValue(':date', $date); diff --git a/www/templates/records/index.html.twig b/www/templates/records/index.html.twig new file mode 100644 index 0000000..1c6aacb --- /dev/null +++ b/www/templates/records/index.html.twig @@ -0,0 +1,15 @@ +{% extends "base.html.twig" %} + +{% block content %} +

{{ "Records" }}

+ {% set endpoint = "records" %} + {% include "utils/calendar.html.twig" %} + {% if records is defined and records | length > 0 %} + + {% endif %} + +{% endblock %} \ No newline at end of file diff --git a/www/templates/today/index.html.twig b/www/templates/today/index.html.twig index 8475a43..b69dd5d 100644 --- a/www/templates/today/index.html.twig +++ b/www/templates/today/index.html.twig @@ -10,7 +10,8 @@ {{ date | format_datetime("full", "none") }} {% endif %} - {% include "today/calendar.html.twig" %} + {% set endpoint = "today" %} + {% include "utils/calendar.html.twig" %} {# Display a list of records if any, else, print message #} {% if results is defined and results | length > 0 %}