Skip to content

Commit

Permalink
New footer template, bump schema version, #14
Browse files Browse the repository at this point in the history
Refactored the header and footer, all courses must be updated and re-imported.
Added a course.json schema and schema validation as part of the import
process.
  • Loading branch information
danmichaelo committed Aug 16, 2018
1 parent e63bf14 commit c075579
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 30 deletions.
7 changes: 5 additions & 2 deletions app/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ class Course extends Model
* @var array
*/
protected $casts = [
'header' => 'object',
'footer' => 'object',
'modules' => 'object',
'options' => 'object',

'github_hook' => 'object',
'last_event' => 'object',
'options' => 'object',
];

protected $fillable = ['name', 'modules', 'header', 'headertext', 'footer', 'repo'];
protected $fillable = ['name', 'modules', 'header', 'footer', 'repo', 'domain'];

/**
* Get the route key for the model.
Expand Down
16 changes: 15 additions & 1 deletion app/CourseLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
use Despark\ImagePurify\Interfaces\ImagePurifierInterface;
use Illuminate\Console\Command;
use Michelf\MarkdownExtra;
use Swaggest\JsonSchema\Schema;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

class CourseLoader
{
protected $schemaVersion = 2;
protected $schema;

public function __construct(MarkdownExtra $markdown, ImagePurifierInterface $purifier)
{
$this->markdown = $markdown;
$this->purifier = $purifier;
$this->schema = Schema::import(json_decode(file_get_contents(resource_path('course.schema.json'))));
}

public function setOutput(\Illuminate\Console\OutputStyle $out)
Expand Down Expand Up @@ -148,9 +153,18 @@ protected function setData($obj, $data, $props, $optionalProps = [])
*/
public function courseFromJson($courseName, $data)
{
if (($data->version ?? 0) !== $this->schemaVersion) {
throw new ImportError(sprintf(
'This version of Scroll requires a course.json schema version %d.',
$this->schemaVersion
));
}

// Validate
$this->schema->in($data);

$props = [
'header',
'headertext',
'footer',
'modules',
'repo',
Expand Down
21 changes: 20 additions & 1 deletion app/Http/Controllers/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@

class CourseController extends Controller
{
/**
* Utility method to join a string with a natural language conjunction at the end.
* https://gist.github.com/angry-dan/e01b8712d6538510dd9c
*/
protected function naturalLanguageJoin(array $list, $conjunction = 'og')
{
$last = array_pop($list);
if ($list) {
return implode(', ', $list) . ' ' . $conjunction . ' ' . $last;
}
return $last;
}

/**
* Display a list of courses.
Expand All @@ -24,8 +36,15 @@ public function index(Request $request)
*/
public function show(Request $request, Course $course)
{
$publishers = array_map(function ($item) {
return sprintf('<a href="%s">%s</a>', $item->link, $item->label);
}, $course->footer->publishers);

$response = response()
->view('courses.show', ['course' => $course])
->view('courses.show', [
'course' => $course,
'publishers' => $this->naturalLanguageJoin($publishers),
])
->setLastModified($course->updated_at)
->setPublic()
->setExpires(Carbon::now()->addDay());
Expand Down
3 changes: 3 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/* Set locale for date formatting */
setlocale(LC_TIME, ['nb_NO', 'no_NO']);

/*
|--------------------------------------------------------------------------
| Create The Application
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"require": {
"php": ">=7.0.0",
"aacotroneo/laravel-saml2": "dev-remove_mcrypt",
"doctrine/dbal": "^2.5",
"despark/image-purify": "dev-up-symf4",
"doctrine/dbal": "^2.5",
"fideloper/proxy": "^4.0",
"graham-campbell/github": "^7.3",
"guzzlehttp/guzzle": "^6.3",
Expand All @@ -21,6 +21,7 @@
"michelf/php-markdown": "^1.7",
"php-http/guzzle6-adapter": "^1.1",
"squizlabs/php_codesniffer": "^3.2",
"swaggest/json-schema": "^0.12.4",
"symfony/process": "^4.0"
},
"require-dev": {
Expand Down
51 changes: 51 additions & 0 deletions database/migrations/2018_08_15_221459_refactor_header_footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
class RefactorHeaderFooter extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('courses', function (Blueprint $table) {
$table->dropColumn('header');
$table->dropColumn('headertext');
$table->dropColumn('footer');
});

Schema::table('courses', function (Blueprint $table) {
$table->json('header')->default('{}');
$table->json('footer')->default('{}');

$table->string('domain')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('courses', function (Blueprint $table) {
$table->dropColumn('domain');

$table->dropColumn('header');
$table->dropColumn('footer');
});

Schema::table('courses', function (Blueprint $table) {
$table->string('header');
$table->text('headertext');
$table->string('footer');
});
}
}
Binary file added public/images/uio-segl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 59 additions & 6 deletions resources/assets/sass/app.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
// Bootstrap
@import '~bootstrap/scss/bootstrap';

$break-sm: 768px
$break-md: 992px
$break-md: 1200px

/*******************************************************************
* Quiz
*******************************************************************/
Expand All @@ -20,18 +24,30 @@
* Overall page layout
*******************************************************************/

.padded
padding-right: 15px
padding-left: 15px

.module .padded
padding-top: 15px
padding-bottom: 20px

body
padding-bottom: 0cm
overflow-y: scroll // to avoid center-column from jumping when scrollbar appears
position: relative // for scroll-spy
padding-color: black

#app
margin-top: 2em
padding-top: 0.5em
@media (min-width: $break-sm)
padding-top: 1.5em

.container-fluid
max-width: 960px

.uio-banner

header
background-size: 100%
background-position: center center;
background-margin: 0 auto
Expand All @@ -57,6 +73,43 @@ body
h3
font-size: 1.6rem

footer
background-color: black
color: white
font-size: 80%
font-family: arial, sans-serif

a:link, a:visited
color: #bbb

.container-fluid
display: flex
align-items: center

@media (max-width: $break-sm)
flex-direction: column

.logo
background-image: url(/images/uio-segl.png)
background-repeat: no-repeat
background-position: center
flex: 0 0 auto
width: 130px
height: 130px
background-size: 110px 110px

@media (max-width: $break-sm)
width: 100px
height: 100px
background-size: 90px 90px


> div
flex: 1 0 auto
margin-left: 10px
margin-right: 10px


#footer
background-color: black

Expand All @@ -72,16 +125,16 @@ body


@media (max-width: 1200px)
#app, #footer > div
.container-fluid
margin-left: auto

@media (min-width: 1200px)
#app, #footer > div
.container-fluid
margin-left: 10vw


@media (max-width: 900px)
.uio-banner
header
height: 22vw

h1
Expand All @@ -103,7 +156,7 @@ body


@media (min-width: 900px)
.uio-banner
header
height: 198px

h1
Expand Down
Loading

0 comments on commit c075579

Please sign in to comment.