source-data / sdash

A dashboard for sharing SmartFigures
MIT License
2 stars 0 forks source link

SDash (Laravel)

See Laravel docs at https://laravel.com/docs/master

See database schema at https://dbdiagram.io/

See REST naming conventions at https://restfulapi.net/resource-naming/

Installation

The .env file found in the project route (or created by you from the .env.example file) needs to have these properties filled in, referring to the URL where the VUE application is mounted and the URL for API calls.

MIX_DASHBOARD_URL=http://sdash.laravel
MIX_API_URL=http://sdash.laravel/api
MIX_SMART_TAG_URL=https://smtag.sourcedata.io/api/v1/tag

For local deployment and development with docker and docker-compose see docker-compose/docker_help.md.

Deployment

Project deployment is in the process of being configured with Deployer.

Deployer will be installed as a project dependency when you run composer install

You should configure the deploy.php file to contain the correct hostname and deploy path for this project.

Running php vendor/bin/dep deploy dev will deploy the master branch to the host called "dev" in the config file.

ImageMagick

To convert PDFs into jpgs, we need the imagemagick library and the PHP module to access it.

sudo apt-get update && sudo apt-get install -y imagemagick php-imagick

See https://stackoverflow.com/questions/37599727/php-imagickexception-not-authorized to solve a not authorised error from ImageMagick

Restart php-fpm and nginx

Database Seeding

Run php artisan db:seed to seed the database with some test data This includes a demo user with SuperAdmin privileges

You can completely refresh your database (losing any non-seeded data) by running php artisan migrate:refresh --seed

Unit Testing

This project uses Laravel's own integration of PHPUnit. You should set up a testing database using MySQL in order to resemble the real database.

You should create a .env.testing file in the project root. This should be an exact copy of your .env file except the database details.

For example, the database details in .env.testing could be:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sdash_laravel_testing
DB_USERNAME=test_user
DB_PASSWORD=test_password

You would need to create this database and user on your local MySQL installation. Once you've created the empty database, there is no need to run migrations - Laravel will run the migrations when needed for the tests.

To run the test suite:

php artisan test

See also: Laravel Testing

End-to-end testing

Install the dev dependencies to pull in the chromedriver & geckodriver packages:

npm install --save-dev

Start SDash locally, then run the actual tests in Chrome & Firefox:

npx nightwatch --env firefox,chrome

To run a single test, for example during debugging, pass the path to the test spec:

npx nightwatch ./tests/e2e/specs/userProfile.spec.js --env firefox --testcase 'check that a user without an avatar can change and delete it'

API Endpoints Needed

User

Panels

Groups

Images

Figures

Files

Tags

Fontawesome

See https://www.npmjs.com/package/@fortawesome/vue-fontawesome for instructions on using the FontAwesome library for Vue

e.g.

<font-awesome-icon icon="save" size="lg"/>
<font-awesome-icon icon="trash-alt" size="lg"/>

Bootstrap-Vue

Instructions for the pre-built component library of Bootstrap Components can be found here https://bootstrap-vue.js.org/

Post deployment notes

The following command should be run once in the project root on the first deployment to populate the file_categories table: php artisan db:seed --class=FileCategoriesTableSeeder

This command should be run to populate the licenses database: php artisan db:seed --class=LicensesTableSeeder

If seeding the database with generated records, or updating the database from an earlier installation, you may need to generate the panel-author relationships. To do so, run the following mysql command:

insert into panel_user(user_id, panel_id, role, `order`, created_at, updated_at)
select  p.user_id,
p.id as panel_id,
'corresponding' as role,
0 as `order`,
NOW() as created_at,
NOW() as updated_at
from panels p;

Note: When a new user registers, the list of external authors is checked for their email address. If anyone has added their address as an external author to a panel, this is converted into a registered author and the newly-registered user is given the author role on the panel.