Skip to content
2 changes: 1 addition & 1 deletion fixtures/cameo/outdoor-par-tri-12.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Outdoor PAR Tri 12",
"shortName": "OutTri12",
"type": "Color Changer",
"categories": ["Color Changer"],
"meta": {
"authors": ["FloEdelmann"],
"createDate": "2017-02-24",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cameo/thunder-wash-100-rgb.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Thunder Wash 100 RGB",
"shortName": "CLTW100RGB",
"type": "Strobe",
"categories": ["Strobe", "Blinder", "Color Changer"],
"manualURL": "http://adamhall.invaliddomain.de/out/media/downloads/MARKEN/CAMEO/CLTW100RGB/CLTW100RGB_Cameo_Bedienungsanleitung_EN_DE_FR_ES_PL_IT.pdf",
"meta": {
"authors": ["FloEdelmann"],
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cameo/thunder-wash-100-w.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Thunder Wash 100 W",
"shortName": "CLTW100W",
"type": "Strobe",
"categories": ["Strobe", "Blinder"],
"manualURL": "http://adamhall.invaliddomain.de/out/media/downloads/MARKEN/CAMEO/CLTW100W/CLTW100W_Cameo_Bedienungsanleitung_EN_DE_FR_ES_PL_IT.pdf",
"meta": {
"authors": ["FloEdelmann"],
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cameo/thunder-wash-600-rgb.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Thunder Wash 600 RGB",
"shortName": "CLTW600RGB",
"type": "Strobe",
"categories": ["Strobe", "Blinder", "Color Changer"],
"manualURL": "http://adamhall.invaliddomain.de/out/media/downloads/MARKEN/CAMEO/CLTW600RGB/CLTW600RGB_Cameo_Bedienungsanleitung_EN_DE_FR_ES_PL_IT.pdf",
"meta": {
"authors": ["FloEdelmann"],
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cameo/thunder-wash-600-w.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Thunder Wash 600 W",
"shortName": "CLTW600W",
"type": "Strobe",
"categories": ["Strobe", "Blinder"],
"manualURL": "http://adamhall.invaliddomain.de/out/media/downloads/MARKEN/CAMEO/CLTW600W/CLTW600W_Cameo_Bedienungsanleitung_EN_DE_FR_ES_PL_IT.pdf",
"meta": {
"authors": ["FloEdelmann"],
Expand Down
2 changes: 1 addition & 1 deletion fixtures/gruft/ventilator.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Ventilator",
"shortName": "Venti",
"type": "Fan",
"categories": ["Fan"],
"comment": "(C) Görli + Edelnörd 2016",
"meta": {
"authors": ["FloEdelmann"],
Expand Down
2 changes: 1 addition & 1 deletion fixtures/lightmaxx/platinum-mini-tri-par.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Platinum Mini TRI-PAR",
"shortName": "MiniTri",
"type": "Color Changer",
"categories": ["Color Changer"],
"comment": "Platinum Line Mini TRI-PAR 7x3 Watt",
"meta": {
"authors": ["FloEdelmann"],
Expand Down
2 changes: 1 addition & 1 deletion fixtures/lightmaxx/vega-zoom-wash.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Vega Zoom Wash",
"shortName": "VegaZoomWash",
"type": "Moving Head",
"categories": ["Moving Head", "Color Changer"],
"manualURL": "https://www.musicstore.de/INTERSHOP/web/WFS/MusicStore-MusicStoreShop-Site/de_DE/-/EUR/ViewProductAttachment-ResolveManualURL?File=DE_LIG0013617-000.pdf",
"meta": {
"authors": ["FloEdelmann"],
Expand Down
13 changes: 11 additions & 2 deletions fixtures/register.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,26 @@
"vega-zoom-wash"
]
},
"types": {
"categories": {
"Color Changer": [
"cameo/outdoor-par-tri-12",
"lightmaxx/platinum-mini-tri-par"
"cameo/thunder-wash-100-rgb",
"cameo/thunder-wash-600-rgb",
"lightmaxx/platinum-mini-tri-par",
"lightmaxx/vega-zoom-wash"
],
"Strobe": [
"cameo/thunder-wash-100-rgb",
"cameo/thunder-wash-100-w",
"cameo/thunder-wash-600-rgb",
"cameo/thunder-wash-600-w"
],
"Blinder": [
"cameo/thunder-wash-100-rgb",
"cameo/thunder-wash-100-w",
"cameo/thunder-wash-600-rgb",
"cameo/thunder-wash-600-w"
],
"Fan": [
"gruft/ventilator"
],
Expand Down
10 changes: 6 additions & 4 deletions generate-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
let register = {
filesystem: {},
manufacturers: {},
types: {}
categories: {}
};

const fixturePath = path.join(__dirname, 'fixtures');
Expand Down Expand Up @@ -38,10 +38,12 @@ try {
manufacturerName: manufacturers[man].name
};

if (!(fixData.type in register.types)) {
register.types[fixData.type] = [];
for (const cat of fixData.categories) {
if (!(cat in register.categories)) {
register.categories[cat] = [];
}
register.categories[cat].push(man + '/' + fix);
}
register.types[fixData.type].push(man + '/' + fix);
}
}
}
Expand Down
93 changes: 29 additions & 64 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ app.engine('js', (filePath, options, callback) => {

let opts = {
manufacturers: manufacturers,
manufacturersIndex: register.manufacturers,
typesIndex: register.types,
register: register,
baseDir: __dirname,
messages: getMessages()
};
Object.assign(opts, options);
Expand Down Expand Up @@ -57,38 +57,25 @@ fs.readFile(path.join(__dirname, 'fixtures', 'register.json'), 'utf8', (error, d
register = JSON.parse(data);
});

app.get('/', (request, response) => {
response.render('pages/index');
});

const staticPages = {
'/index': 'Open Fixture Library',
'/about': 'About - Open Fixture Library',
'/categories': 'Categories - Open Fixture Library'
};

app.use((request, response, next) => {
let page = request.originalUrl;
if (page == '/') {
page = '/index';
}
app.get('/about', (request, response) => {
response.render('pages/about');
});

if (page in staticPages) {
response.render('pages' + page, {
title: staticPages[page]
});
}
else {
next();
}
app.get('/categories', (request, response) => {
response.render('pages/categories');
});

app.get('/manufacturers', (request, response) => {
response.render('pages/manufacturers', {
title: 'Manufacturers - Open Fixture Library'
});
response.render('pages/manufacturers');
});

app.get('/search', (request, response) => {
response.render('pages/search', {
title: 'Search - Open Fixture Library'
query: request.query
});
});

Expand All @@ -100,51 +87,29 @@ app.use((request, response, next) => {


if (segments.length == 1 && segments[0] in manufacturers) {
renderSingleManufacturer(response, segments[0]);
response.render('pages/single_manufacturer', {
man: segments[0]
});
return;
}
else {
if (segments.length == 2 && segments[0] in manufacturers && register.manufacturers[segments[0]].indexOf(segments[1]) != -1) {
renderSingleFixture(response, segments[0], segments[1]);
return;
}
else if (segments.length == 2 && segments[0] in manufacturers && register.manufacturers[segments[0]].indexOf(segments[1]) != -1) {
response.render('pages/single_fixture', {
man: segments[0],
fix: segments[1]
});
return;
}

response.status(404).render('pages/404', {
title: 'Page not found - Open Fixture Library'
})
});


function renderSingleManufacturer(response, man) {
let fixtures = [];

for (let fix of register.manufacturers[man]) {
const fixData = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', man, fix + '.json'), 'utf-8'));

fixtures.push({
path: man + '/' + fix,
name: fixData.name
else if (segments.length == 2 && segments[0] === 'categories' && decodeURIComponent(segments[1]) in register.categories) {
response.render('pages/single_category', {
type: decodeURIComponent(segments[1])
});
return;
}

response.render('pages/single_manufacturer', {
title: manufacturers[man].name + ' - Open Fixture Library',
manufacturer: manufacturers[man],
fixtures: fixtures
});
}

function renderSingleFixture(response, man, fix) {
const fixData = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', man, fix + '.json'), 'utf-8'));
console.log(`page ${request.originalUrl} [${segments}] not found`);

response.render('pages/single_fixture', {
title: `${manufacturers[man].name} ${fixData.name} - Open Fixture Library`,
manufacturer: manufacturers[man],
manufacturerPath: '/' + man,
fixture: fixData
});
}
response.status(404).render('pages/404');
});


function getMessages() {
Expand All @@ -168,4 +133,4 @@ function addFileReadError(text, error) {
type: 'error',
text: `${text}<br /><code>${error.toString()}</code>`
});
}
}
12 changes: 9 additions & 3 deletions tests/fixtures_valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let usedShortNames = [];

const dateRegExp = /^\d{4}-\d{2}-\d{2}$/;
const hexRegExp = /^#[0-9a-f]{6}$/;
const fixtureCategories = ['Other', 'Color Changer', 'Dimmer', 'Effect', 'Fan', 'Flower', 'Hazer', 'Laser', 'Moving Head', 'Scanner', 'Smoke', 'Strobe', 'Blinder'];
const channelTypes = ['Intensity', 'Strobe', 'Shutter', 'Speed', 'SingleColor', 'MultiColor', 'Gobo', 'Prism', 'Pan', 'Tilt', 'Beam', 'Effect', 'Maintenance', 'Nothing'];
const channelColors = ['Generic', 'Red', 'Green', 'Blue', 'Cyan', 'Magenta', 'Yellow', 'Amber', 'White', 'UV', 'Lime'];

Expand Down Expand Up @@ -64,10 +65,15 @@ function checkFixture(filename) {
delete fixture.name;
delete fixture.shortName;

if (!('type' in fixture) || typeof fixture.type !== 'string') {
resolveError(`type missing / wrong type in file '${filename}'.`, null, resolve);
if (!('categories' in fixture) || !Array.isArray(fixture.categories)) {
return resolveError(`categories missing / wrong type in file '${filename}'.`, null, resolve);
}
delete fixture.type;
for (const cat of fixture.categories) {
if (fixtureCategories.indexOf(cat) == -1) {
resolveError(`category '${cat}' invalid in file '${filename}'.`, null, resolve);
}
}
delete fixture.categories;

if ('comment' in fixture && typeof fixture.comment !== 'string') {
resolveError(`comment has wrong type in file '${filename}'.`, null, resolve);
Expand Down
13 changes: 11 additions & 2 deletions tests/http_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ const statusCodes = {
'manufacturers',
'categories',
'about',
'search'
'search',
'search?q=bla'
],
'404': [
'bla',
'about/bla',
'categories/bla',
'categories/Blinder/bla',
'manufacturers/gruft',
'gruft/bla',
'cameo/ventilator',
'gruft/thunder-wash-600-rgb',
'gruft/ventilator/bla',
]
}
Expand All @@ -32,6 +35,12 @@ for (const man in register.manufacturers) {
statusCodes['200'].push(path.join(man, fixture));
}
}
for (const cat in register.categories) {
statusCodes['200'].push('categories/' + cat);
if (cat !== encodeURIComponent(cat)) {
statusCodes['200'].push('categories/' + encodeURIComponent(cat));
}
}


// start server
Expand Down
2 changes: 2 additions & 0 deletions views/pages/404.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = function(options) {
options.title = 'Page not found - Open Fixture Library';

let str = require('../partials/header')(options);

str += '<h1>404 - Not found</h1>';
Expand Down
2 changes: 2 additions & 0 deletions views/pages/about.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = function(options) {
options.title = 'About - Open Fixture Library';

let str = require('../partials/header')(options);

str += '<h1>About</h1>';
Expand Down
24 changes: 22 additions & 2 deletions views/pages/categories.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
module.exports = function(options) {
const {register} = options;

options.title = 'Categories - Open Fixture Library';

let str = require('../partials/header')(options);

str += '<h1>Categories</h1>'
str += '<p>list of all categories</p>';
str += '<h1>Categories</h1>';

for (type in register.categories) {
const num = register.categories[type].length;
const numFixtures = `${num} fixture${num == 1 ? '' : 's'}`;
const link = '/categories/' + encodeURIComponent(type);

str += '<section class="type">';
str += '<h2>' + (num > 0 ? `<a href="${link}">${type}</a>` : type) + '</h2>';

str += '<div class="fixtures">' + numFixtures;
if (num > 0) {
str += ` - <a href="${link}">View them</a>`;
}
str += '</div>';

str += '</section>';
}

str += require('../partials/footer')(options);

Expand Down
2 changes: 2 additions & 0 deletions views/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = function(options) {
options.title = 'Open Fixture Library';

let str = require('../partials/header')(options);

str += '<h1>Open Fixture Library</h1>';
Expand Down
Loading