Browse Source

OSAMC branding and tailored for uberspace subdomain

master
Nils 1 year ago
parent
commit
3bbcc5a712
9 changed files with 153 additions and 44 deletions
  1. +1
    -0
      data/osamc
  2. +25
    -0
      public/javascripts/worker.js
  3. +29
    -9
      public/stylesheets/custom.css
  4. +10
    -2
      public/stylesheets/style.css
  5. +7
    -4
      routes/index.js
  6. +74
    -22
      routes/socket.js
  7. +1
    -0
      source.txt
  8. +2
    -4
      views/index.pug
  9. +4
    -3
      views/pad.pug

+ 1
- 0
data/osamc View File

@@ -0,0 +1 @@
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \nDie Treffen im März und April fallen \"dank\" Corona-Pandemie aus. \nBis vielleicht Mai, Nils\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\nProgramm für Mittwoch, den 20. Mai 2020, 19:00\n===================================================\n\n\nVorstellungsrunde, Begrüßung, Organisation und Internes\nWillkommen, Vorstellungsrunde, Anwesenheit, Mailingliste, Rückschau\n---------------------------------------------------\n Anwesend: \n\n\nNews aus der Open Source Audio Welt und Medientipps\nVeranstaltungen, Releases, Termine, Webseiten, Videos, Bücher, Tutorials etc.\n---------------------------------------------------\n\n* Freie Unterrichtsmaterialien (OpenBooks) für den Musikunterricht (Theorie und Praxis)\n https://www.kaiser-ulrich.de/publikationen/openbooks\n* Molekül Festival, 20-24. Mai 2020, Südstadt, ähnlich wie ein BarCamp, 50€ TN-Gebühr, https://www.molekuel-festival.de\n* Open Woodwind Project - https://www.youtube.com/watch?v=7SbSDnqZMzk (erstes richtiges Video seit Jahren)\n* \"Synth Wizards\", praktisch ne \"DMAX\"-Serie für nen Synth-Repair-Shop https://www.youtube.com/playlist?list=PLLNZ36qP29I7xrabeFtg184WiEQl0QS6_\n\nFlohmarkt\nHardware und Zeug\n---------\n\n\nKleine und Große Vorträge, Demonstrationen etc\nBitte Programmvorschläge und Ankündigungen hier eintragen (mit Namensnennung).\n----------------------------------------------\nNils' Audio-Distribution für die Schule - Aus der VirtualMachine in den Klassenraum (nils)\n\n\n\nQuestions & Answers - Freie Diskussionsrunde\nSpontane Fragen und Antworten zu Programmen, Workflows, Musik, Musiktheorie und allem Anderen\n-----------------------------------------------\n\n\nAusklang"

+ 25
- 0
public/javascripts/worker.js View File

@@ -12,6 +12,9 @@ if (f.substr(f.length - 1) == '/') {
pathname = temp[temp.length - 1]
}

//Hack Path to be always 'osamc'. The server only reacts to this, eventhough we could technically request other data
pathname = 'osamc';

// Ask server latest data
socket.emit('sync', { path: pathname })

@@ -33,3 +36,25 @@ function processText () {
cache = x
}
}

function customTab () {
//https://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea#
if(event.keyCode===9){
event.preventDefault();

var textarea = document.getElementById('text');

var start = textarea.selectionStart;
var end = textarea.selectionEnd;

// set textarea value to: text before caret + tab + text after caret
var v = textarea.value;
var s = textarea.selectionStart;
var e = textarea.selectionEnd;
textarea.value = v.substring(0, s) + ' ' + v.substring(e);

// put caret at right position again
textarea.selectionStart =
textarea.selectionEnd = start + 4;
}
}

+ 29
- 9
public/stylesheets/custom.css View File

@@ -1,21 +1,41 @@
body {
padding: 0px;
color: #000000;
font-family:
"SFMono-Regular",
Consolas,
"Liberation Mono",
Menlo,
Courier,
monospace;
}

a {
color: teal;
}


#text {
font-size: 200%;
font-size: 100%;

resize: none;
resize: both;
position: fixed;
border: none;
outline: none;
overflow: scroll;

top:0;
left:0;
right:0;
bottom:0;

width: 100%;
height: 95%;
width: 90%;
height: 750px;

margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;

caret-color: teal;

color: #000000;
background-color: #f0f0f0;
}


+ 10
- 2
public/stylesheets/style.css View File

@@ -1,8 +1,16 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
color: #000000;
font-family:
"SFMono-Regular",
Consolas,
"Liberation Mono",
Menlo,
Courier,
monospace;
}

a {
color: #00B7FF;
color: teal;
}

+ 7
- 4
routes/index.js View File

@@ -1,11 +1,14 @@
var express = require('express')
var shortid = require('shortid')
var router = express.Router()

/* GET home page. */
router.get('/', function (req, res, next) {
var sid = shortid.generate()
res.render('index', { title: 'Welcome to Pad', buttonLbl: 'Get started', id: sid })
router.get('/', function (req, res, next) { /* user-request, server-response, function next*/
/* var sid = shortid.generate() */
/* res.render('index', { title: 'Leere OSAMC-Planung. Da ist wohl was schiefgegangen.', buttonLbl: 'Get started', id: sid }) */
/* res.render('index', { title: 'Leere OSAMC-Planung. Da ist wohl was schiefgegangen.', buttonLbl: 'Get started', id: "osamc" }) */
// res.render('pad', { title: 'Pad', temp: "Hello" })
res.render('pad', { title: 'Pad'})

})

module.exports = router

+ 74
- 22
routes/socket.js View File

@@ -1,6 +1,42 @@
var app = require('express')
var shortid = require('shortid')
var router = app.Router()
var fs = require('fs')

//from https://www.gregjs.com/javascript/2016/checking-whether-a-file-directory-exists-without-using-fs-exists/
function isDirSync(aPath) {
try {
return fs.statSync(aPath).isDirectory();
}
catch (e) {
if (e.code === 'ENOENT') {
return false;
} else {
throw e;
}
}
}

function checkIfFile(file, cb) {
fs.stat(file, function fsStat(err, stats) {
if (err) {
if (err.code === 'ENOENT') {
return cb(null, false);
} else {
return cb(err);
}
}
return cb(null, stats.isFile());
});
}

/* var dataDir = 'data/'; */
var dataDir = 'data/';

if (!isDirSync(dataDir)) {
fs.mkdirSync(dataDir);
console.log('Folder created: ' + dataDir);
}

module.exports = function (io) {
var welcomeMessage = 'Pad created! Share the URL with a friend to edit text in real-time.'
@@ -11,15 +47,39 @@ module.exports = function (io) {
console.log('A user connected')

// Handle sync request
socket.on('sync', function (data) {
socket.on('sync', function (data) {

// Hack Data path to be always 'osamc'
data.path = 'osamc';
console.log(data);
if (pages.has(data.path)) {
// Page exists, notify with pad data
notify(socket, pages.get(data.path), data.path)
console.log('Paste accessed: ' + data.path)
} else {
// Page doesn't exist, notify with new pad
notify(socket, '', data.path)
console.log('Created paste: ' + data.path)
// Page doesn't exist
// so check if file exists
checkIfFile(dataDir + data.path, function(err, isFile) {
if (isFile) {
console.log('File found: ' + data.path)
// read the file
fs.readFile(dataDir + data.path, (err, dataFromFile) => {
if (err) throw err; //create a new pad?
let dataParsed = JSON.parse(dataFromFile);
//console.log('Read data from file:')
//console.log(dataParsed);
pages.set(data.path, dataParsed)
notify(socket, pages.get(data.path), data.path)
});
}
else
{
//page or file doesn't exist, notify with new pad
notify(socket, '', data.path)
console.log('Created paste: ' + data.path)
}
});
}

// Remove junk objects from Map, save space
@@ -27,11 +87,19 @@ module.exports = function (io) {
})

// Handle incoming data from user
socket.on('data', function (data) {
socket.on('data', function (data) {
//Hack data.path to be always osamc. We only have one pad
data.path = 'osamc';
//console.log(data);
// Update pad data in memory
pages.set(data.path, data.text)
var curr = pages.get(data.path)

// Update pad data in file
let padContent = JSON.stringify(data.text); //pads content
fs.writeFile(dataDir + data.path, padContent, (err) => {
if (err) throw err;
// console.log('Data written to file');
});
// Notify everyone of update
notifyAll(socket, curr, data.path)
})
@@ -56,21 +124,5 @@ module.exports = function (io) {
}
}

/* GET pad by unique id */
router.get('/:id', function (req, res, next) {
res.render('pad', { title: 'Pad', temp: welcomeMessage })
})

/* Handle POST, redirect to GET pad by unique id */
router.post('/:id', function (req, res, next) {
res.render('pad', { title: 'Pad', temp: welcomeMessage })
})

/* Handle index requests for /Pad */
router.get('/', function (req, res, next) {
var sid = shortid.generate()
res.render('index', { title: 'Welcome to Pad', buttonLbl: 'Get started', id: sid })
})

return router
}

+ 1
- 0
source.txt View File

@@ -0,0 +1 @@
https://github.com/petercunha/Pad

+ 2
- 4
views/index.pug View File

@@ -13,8 +13,6 @@ html
//-
Bootstrap 3.3.7 CSS

link(href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", rel="stylesheet", integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u", crossorigin="anonymous")
link(rel="icon" href="https://getbootstrap.com/favicon.ico")

body
.container
@@ -28,5 +26,5 @@ html
//-
Bootstrap 3.3.7 JS and JQuery 3.1.1

script(src="https://code.jquery.com/jquery-3.1.1.slim.min.js", integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=", crossorigin="anonymous")
script(src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js", integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa", crossorigin="anonymous")

+ 4
- 3
views/pad.pug View File

@@ -2,13 +2,14 @@ doctype html
html

head
title= title
title= 'OSAMC Planung'

link(rel='stylesheet', href='/stylesheets/custom.css')
link(rel="icon" href="https://getbootstrap.com/favicon.ico")

script(src="/socket.io/socket.io.js" type="text/javascript")
script(src="/javascripts/worker.js", type="text/javascript")

body
textarea(id="text", autocomplete="off", onkeyup="processText()", placeholder=temp)
p Was bisher geschah: <a href="https://www.osamc.de/protokolle">Protokolle</a> | <a href="https://www.osamc.de/protokolle.php" >Alle Protokolle auf einer Seite</a> | <a href="https://www.osamc.de/archiv">Vortragsarchiv</a>
hr
textarea(id="text", wrap="off", autofocus="on", autocomplete="off", onkeydown="customTab()", onkeyup="processText()", placeholder=temp)

Loading…
Cancel
Save