Git Product home page Git Product logo

trip2's Introduction

Installation

Start

It's recommended to use Laravel Valet for development. Follow its instructions. https://laravel.com/docs/master/valet

It's also recommended to install composer require global hirak/prestissimo first.

Then:

git clone https://github.com/tripikad/trip2
cd trip2
composer install
cp .env.example .env
php artisan key:generate
php artisan dusk:update --detect
yarn # or npm install
npm run dev

Databases

mysqladmin -uroot create trip
mysqladmin -uroot create trip2

Optionally use https://www.sequelpro.com or https://tableplus.com/ to set up the databases. Ask for access to staging server to get the latest trip2 database dump and migrate the data over, either using db client or run

mysql -uroot trip2 < dump.sql

Getting production images

In your .env file set the following parameter:

IMAGE_PATH=https://trip.ee/images/

Redis

To get production-level caching experience, install Redis using Homebrew and then add this to .env files:

CACHE_DRIVER=redis

Nginx cache

To test the local reverse proxy cache, edit /usr/local/etc/nginx/valet/valet.conf file:

  1. Add the following to the top of the file:
fastcgi_cache_path /tmp/nginx levels=1:2 keys_zone=TRIP2:256m inactive=60m use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
  1. After the
fastcgi_param SCRIPT_FILENAME /.../

line add the following:

fastcgi_cache TRIP2;
fastcgi_ignore_headers Set-Cookie;
fastcgi_hide_header Set-Cookie;
fastcgi_pass_header Set-Cookie;
fastcgi_cache_bypass $cookie_logged $is_args;
fastcgi_no_cache $cookie_logged $is_args;
add_header X-Cache $upstream_cache_status;

and then run

valet restart

To clear the cache, run

rm -R /tmp/nginx/*
valet restart

Testing

Preparation

  1. Make sure you use latest Chrome.

  2. Run

    php artisan dusk:update --detect
    

    If you want to run Dusk tests with previous version of Chrome you will need specify a version of Dusk update. Read more here https://github.com/staudenmeir/dusk-updater

  3. Make sure the FULL_BASE_URL in .env file points to the local Laravel URL of your development environment

Running all tests

npm run test

Running feature and browser tests separately

./vendor/bin/phpunit
php artisan dusk

Formatting code

To format the php, caa, js and vue files we use Prettier.

It is recommended to use VS Code Prettier plugin and set Format on Save setting to true.

To format all files in one go, run

npm run prettier

There is also a automatic task in Github to run npm run prettier on each pull request.

Frontend development

NPM commands

First make sure FULL_BASE_URL refers to local development URL.

npm run dev # runs watch + live
npm run watch # Unminified and fast dev build, recompiling on file change
npm run live # Live reload in browser
npm run devbuild # Unminified and fast dev build
npm run build # Minified and slow production build

Build process

The main entrypoint is ./resources/views/main.js what boots up a Vue instance and includes all the neccessary assets.

JS

Vue components from

./resources/views/components/**/*.vue

are compiled and minified to

./public/dist/main.hash.js

Lazy component loading

Vue components can also be lazy-loaded, most useful for components that have large dependecies.

<template>
    // ...
    <component :is="'Editor'" />
</template>
<script>
export default {
  components: {
    Editor: () =>
      import("../../components_lazy/Editor/Editor.vue")
  },
// ...

This creates an extra packages main.0.hash.js, main.1.hash.js etc which are loaded on demand via ajax when Editor component is on the page.

CSS

Components CSS from

./resources/views/components/**/*.css

and helper CSS from

./resources/views/styles/**/*.css

are concatted, processed using PostCSS (the configuration is at ./postcss.config.js) and saved to

./public/dist/main.hash.css

SVG

SVGs from ./resources/views/svg/**/*.svg

are concat into a SVG sprite, optimized, minified and saved to

./public/dist/main.svg

Frontend architecture: Components

API

Components are located at resources/views/components and are either Laravel Blade or VueJS components.

To show a component use a component() helper:

component('MyComponent')
    ->is('small') // Optional CSS modifier, adds a MyComponent--small class
    ->is('red') // Modifiers can be chained
    ->with('data1', 'Hello') // Passing a variable, similar to view()->with()
    ->with('data2', 'World'); // Variables can be chained

If there are both Blade and Vue components with the same name, Blade is preferred. You can request a Vue template by chaining a ->vue() method.

Making a component

To make a Blade component, run

php artisan make:component MyComponent

and follow the directions.

To make a Vue component run

php artisan make:component MyComponent --vue

Component CSS

Class naming conventions

We use a hybrid BEM / SUIT naming convention:

Blocks:

.Component {
}
.AnotherComponent {
}

Elements (note the spacing):

.Component__element {
}
.AnotherComponent__anotherElement {
}

Modifiers

.Component--modifier {
}
.AnotherComponent--anotherModifier {
}

Style variables in CSS

Variables are located in /resources/views/styles/styles.js

For CSS, the variables are automatically available:

.Component {
    height: $spacer;
}

Style variables in PHP

Variables in /resources/views/styles/styles.js are exported to config/styles.php during fontent build time and can can be used in PHP files and Blade templates using styles() helper:

<div style="height: {{ styles('spacer') }}">

Style variables in Vue

Variables in /resources/views/styles/variables.json can be used in Vue templates like this:

<div :style="{ height: $styles.spacer }">

and in methods like this

this.$styles.spacer

Fonts

Fonts for headings

Use the $font-heading-xs | $font-heading-sm | $font-heading-md | $font-heading-lg | $font-heading-xl | $font-heading-xxl | $font-heading-xxxl variables that set most of the font details.

Also, it's recommended to reduce contrast and use lighter font colors:

.Component__title {
    font: $font-heading-lg;
    color: $gray-dark;
}
Fonts for shorter plain texts

Use the $font-text-xs | $font-text-sm | $font-text-md | $font-text-lg variables.

.Component__description {
    font: $font-text-md; // The recommended body size
    color: $gray-dark; // For reduced contrast
}
Fonts for longer texts with markup

Use the dedicated Body component:

component('Body')->with('body', $your_html_content);

Third party CSS

When using third party libraries one can import it's CSS from node_modules directory:

@import 'somelibrary/dist/somelibrary.css';

Regions

API

Regions are located at app/Http/Regions and are simple PHP classes to extract rendering specific code chunks out of controllers.

To show a component use a region() helper:

region('MyComponent', $parameter1, $parameter2); // etc

Making a region

To make a region, run

php artisan make:region MyRegion

and follow the directions.

Layouts

API

Layouts are located at resources/views/layouts and are simple wrappers around top-level view().

To show a component use a layout() helper:

layout('One')
    ->with('data1', 'Hello') // Passing a variable
    ->with('data2', 'World') // Variables can be chained
    ->render(); // At the time of writing the final render() is required

By default layout() adds HTTP cache headers for 10 minutes. To disable this, add

layout('One')->cached(false);

Making a layout

At the time of writing there is no helper command to create a layout .

Backend arcitecture

Models

See the PR for entity-relationship diagram:

graph.png

trip2's People

Contributors

kristjanjansen avatar mikkpokk avatar apani avatar kkallasm avatar fredpaist avatar

Stargazers

 avatar Chanif2003 avatar Abraão Pessoa avatar  avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar  avatar  avatar  avatar

trip2's Issues

Create reusable destination autocomplete component

Destination autocomplete search is used in several places in the site, it should be a generic component, ripped out of filters in the content pages.

For destination data it should use either a view composer or use AJAX callback initiated by (Selectize) JS library and served by DestinationController.

The destination data should be cached.

Add static content view

There are some static pages that require a special content type -- about us, for publishers, EULA etc.
Static content needs its own view, views/pages/content/static/show.blade.php without page header and with creator name / creation date.

Also, static content should not be commentable. Add a respective setting content.your_content_type.comments and update ContentController.

Add date formatters

Currently views contain lots of raw created_at->format('Y m d') calls. Replace them with view component for date formatting:

resources/views/component/date/long.blade.php
resources/views/component/date/short.blade.php
resources/views/component/date/relative.blade.php

call them by

@include('date.long', ['created_at' => $content->created_at]) 
@include('date.short', ['created_at' => $content->created_at])
@include('date.relative', ['created_at' => $content->created_at])

and output

2. mai 2015 11:15
2. mai 2015
2 months ago

Allow to log in with legacy Drupal password

Drupal 6 uses md5() alogrithm for password hashing, Laravel uses more secure bcrypt() by default. To allow loggin in with Drupal passwords, the Laravel default alogrithm needs to be changed.

There are several options to do this:

Alternative Hasher service

http://www.howtobuildsoftware.com/index.php/how-do/HIs/php-laravel-sha1-laravel-5-extending-laravel-5-using-sha1-instead-of-bcrypt

(sha1 needs to replaced with md5)

Contextual binding

http://laravel.com/docs/5.1/container#contextual-binding

Parameters:

  • App\Http\Controllers\Auth\LoginController
  • Illuminate\Contracts\Hashing\Hasher
  • App\Hashers\md5Hasher

Mass mailing of new password reset links

These two options above might not be secure enough, ideally is better and more secure to always use bcrypt(). This means old Drupal users need to reset their passwords. This can be automated by sending them password reset e-mails but this can add confusion (outdated e-mails etc).

Rename Topics to Tags

Rename "Topics" to "Tags" everywhere -- from database schema to the translation files.

Implement read status on messages

In showMessages check for message flag and apply the right class

In showMessagesWith update the message table with respective read status (ideally run a backgroud queue for this)

Redirect old destination routes

Terms

Redirect old Drupal /taxonomy/term/{tid} links to new term routes:

  1. If the tid is found in is Destination model, redirect to /destination/{id}
  2. If the tid is found in Topic/Tag model, redirect to /content/forum?tag={id}
  3. If the tid is found in Carrier model, redirect to /content/flight?carrier={id}
  4. Else abort with 404

Put the whole logic to new RedirectController and move the redirect methoud from ContentController to the new controller as well.

Update advertisers page

  • Update http://trip.ee/reklaam

  • Should all users re-confirm the new EULA?

  • Convert text markup to HTML

  • Subheaders to <h4>

  • Contact info to use

    four space indent
    
  • In future needs dynamic content (ad placeholders etc).

Add config for menus

Currently topnav menu gets its links from complex config/content.php file.

Instead, create a simple config/menu.php where all the menus are defined -- topnav, user, footer etc.

Do not overwrite uploaded files with the same name

Currently if files are uploaded and they have the same name and location as exisiting file, they will be overwrited.

Provide as solution:

A) Check for file existance and suffix the file with -1, -2

B) always add unique suffix hash to uploaded files using either str_random() (4 chars is enough) or current time().

Create SVG icon pipeline

Source: coloured SVGs
Target: SVG sprite, scss file

Additional requirements: svg4everybody polyfill

Create Atom feed

Pull in feed generator

https://github.com/RoumenDamianoff/laravel-feed

Define a route

based on exiting Drupal feed URL: /index.atom

Create controller

AtomController and get 15 latest news items:

Content::whereType('news')->whereStatus(1)->latest()->take(15)->get;

and pass them to the feed generator.

If site-wide variables are needed, use config('site.*') variables from /config/site.php (add new ones if neccessary).

Add link to the footer

Reduce CSS size

Currently we only use Bootstrap reset, grid and button styles but include full library to the page. Several options to fix it:

  1. Keep Bootstrap 3 and run it through uncss
  2. Explore Bootstrap 4 and an see if we can include parts of it in a modular way
  3. Use Suzy grids, Bourbon buttons and some standard CSS reset

Email follows

When comment is added, in controller, on 'saved' event in Comment model or on custom event launch a emailFollow queued job that sends a BCC email to all "email subcribers".

  • Do we email subscriber's own comments?
  • Do we delay the sending for spam prevention, editing?

Allow toggling private message scrambling

Currently conversion scrambles private messages to maintain user privacy. Allow to convert the messages unscrambled when needed (conversion in production site).

Create a CONVERT_SCRAMBLE variable in .env file that defaults to true.

Redirect old /node/nid links

Drupal uses /node/{nid} links everywhere. Make sure we redirect them to content/{type}/id. The trick is to get $type.

Convert forum content type into separate types

Content type "misc"

Keep 'forum' content type but associate with new "Vaba teema" topic.

Content type "expat"

All fine

Content type "buysell"

node.category: Depends on #133
node.type: convert to title See http://trip.ee/admin/content/taxonomy/22. Map prefix and term (O: 4310, M: 4311) etc.
node.field_buysellprice_value convert to title suffix
'field_buysellcontact_value convert to body suffix

Also remove ,... prefixes while at it

Add Markdown support

We have some limited text-based markup in our bidy fields: URLs and lists.

Pull down https://gitlab.com/DraperStudio/laravel-parsedown and use it in content, comment and message models as accessor function:

public function getBodyAttribute($value)
{
    $value =  ...markdown...($value);
    $value =  strip_tags($value, config('site.allowedtags'));
    return $value;
}

Try Parsedown::text($value);

Redirect too long legacy content aliases

There are set of aliases that are currently not captured by the *.html regexp. They look like this:

nid: 55956

content/euroopa/hispaania/hispaania-kel-on-soovi-hispaania-elu-minna-nautima-ehk-siis-elama-ja-toole

nid: 55966

content/tere-ja-kes-on-minuga-alates-1-detsembrist-uhinema-minuga-reisile-laeva-kruiisile-miami-flor

The URL length are around 100 to 102 so they can be be captured using {100,}

Convert hardcoded img tags from content

When there is a new Image model, convert hardcoded trip.ee-located images into proper Images with in-content references.

Hardcoded images come mostly from recent news and flight content.

Depends on #53

Clean up content.php

  • consider breakup to separate files /config/content/news.php etc
  • separate index =>, frontpage =>, edit => etc sections
  • move strings to trans()
  • remove redundant options

Add expired/archived state for the content

Run a scheduled task that goes through the content and sets the status flag to 2 as Expired.

Do consider:

  • Some content types will never expire (static content, photos)
  • Does archived state just prevent further commenting or prevents access from the whole item?
  • Do some less-frequent destinations should have more content eg less harsh expiration policy?
  • Is expired content accessible for search engines?
  • Is expired content accessible via (advanced) search?

Email private messages

Create profile field for each user:

email_messages

In controller, on 'saved' event in Message model or on custom event launch a emailMessage queued job that sends a message to receipent (when she has a respective setting enabled).

Decide what to do with old Trip offers

For initial version we keep managing the travel offers in the old Trip site. This requires several steps:

Create Image model

Currently we store image information in Content / User objects in image attribute but we only support one image per model.

Instead, create a Image model and pivot table that links any model with Image, allowing multiple images per model and also re-use of images.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.