Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front-end clean-up #420

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
templates/*.html linguist-language=html+jinja linguist-detectable=true
4 changes: 2 additions & 2 deletions KerbalStuff/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .blueprints.anonymous import anonymous
from .blueprints.api import api
from .blueprints.blog import blog
from .blueprints.lists import lists
from .blueprints.packs import packs
from .blueprints.login_oauth import list_defined_oauths, login_oauth
from .blueprints.mods import mods
from .blueprints.profile import profiles
Expand Down Expand Up @@ -86,7 +86,7 @@ def load_user(username: str) -> User:
app.register_blueprint(blog)
app.register_blueprint(admin)
app.register_blueprint(mods)
app.register_blueprint(lists)
app.register_blueprint(packs)
app.register_blueprint(api)

try:
Expand Down
2 changes: 1 addition & 1 deletion KerbalStuff/blueprints/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def users(page: int) -> Union[str, werkzeug.wrappers.Response]:
@admin.route("/admin/blog")
@adminrequired
def blog() -> str:
return render_template("admin-blog.html")
return render_template("admin-blog_create.html")


@admin.route("/admin/publishers/<int:page>")
Expand Down
2 changes: 1 addition & 1 deletion KerbalStuff/blueprints/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def create_list() -> Union[Dict[str, Any], Tuple[Dict[str, Any], int]]:
game_id=game)
db.add(mod_list)
db.commit()
return {'url': url_for("lists.edit_list", list_id=mod_list.id, list_name=mod_list.name)}
return {'url': url_for("packs.edit_list", list_id=mod_list.id, list_name=mod_list.name)}


@api.route('/api/mod/create', methods=['POST'])
Expand Down
2 changes: 1 addition & 1 deletion KerbalStuff/blueprints/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def edit_blog(id: str) -> Union[str, werkzeug.wrappers.Response]:
if not post:
abort(404)
if request.method == 'GET':
return render_template("edit_blog.html", post=post)
return render_template("blog_edit.html", post=post)
else:
post.title = request.form.get('post-title')
post.text = request.form.get('post-body')
Expand Down
10 changes: 5 additions & 5 deletions KerbalStuff/blueprints/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def update(mod_id: int, mod_name: str) -> str:
check_mod_editable(mod)
game_versions = GameVersion.query.filter(
GameVersion.game_id == mod.game_id).order_by(desc(GameVersion.id)).all()
return render_template("update.html", ga=mod.game, mod=mod, game_versions=game_versions)
return render_template("mod_update.html", ga=mod.game, mod=mod, game_versions=game_versions)


@mods.route("/mod/<int:mod_id>.rss", defaults={'mod_name': None})
Expand Down Expand Up @@ -257,7 +257,7 @@ def edit_mod(mod_id: int, mod_name: str) -> Union[str, werkzeug.wrappers.Respons
check_mod_editable(mod)
if request.method == 'GET':
original = current_user == mod.user
return render_template("edit_mod.html", mod=mod, original=original,
return render_template("mod_edit.html", mod=mod, original=original,
background=mod.background_url(_cfg('protocol'), _cfg('cdn-domain')),
new=request.args.get('new') is not None and original)
else:
Expand Down Expand Up @@ -287,9 +287,9 @@ def edit_mod(mod_id: int, mod_name: str) -> Union[str, werkzeug.wrappers.Respons
mod.description = description.replace('\r\n', '\n')
mod.score = get_mod_score(mod)
if not mod.license:
return render_template("edit_mod.html", mod=mod, error="All mods must have a license.")
return render_template("mod_edit.html", mod=mod, error="All mods must have a license.")
if mod.description == default_description:
return render_template("edit_mod.html", mod=mod, stupid_user=True)
return render_template("mod_edit.html", mod=mod, stupid_user=True)
newly_published = False
if request.form.get('publish', None):
if not mod.published:
Expand Down Expand Up @@ -328,7 +328,7 @@ def edit_mod(mod_id: int, mod_name: str) -> Union[str, werkzeug.wrappers.Respons
@with_session
def create_mod() -> str:
ga = _restore_game_info()
return render_template("create.html", games=get_games(), ga=ga)
return render_template("mod_create.html", games=get_games(), ga=ga)


@mods.route("/mod/<int:mod_id>/stats/downloads", defaults={'mod_name': None})
Expand Down
24 changes: 12 additions & 12 deletions KerbalStuff/blueprints/lists.py → KerbalStuff/blueprints/packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..database import db
from ..objects import Mod, ModList, ModListItem, Game

lists = Blueprint('lists', __name__)
packs = Blueprint('packs', __name__)


def _get_mod_list(list_id: str) -> Tuple[ModList, Game, bool]:
Expand All @@ -27,9 +27,9 @@ def _get_mod_list(list_id: str) -> Tuple[ModList, Game, bool]:
return mod_list, ga, editable


@lists.route("/packs", defaults={'gameshort': None})
@lists.route("/packs/<gameshort>")
def packs(gameshort: Optional[str]) -> str:
@packs.route("/packs", defaults={'gameshort': None})
@packs.route("/packs/<gameshort>")
def packs_list(gameshort: Optional[str]) -> str:
game = None if not gameshort else get_game_info(short=gameshort)
query = ModList.query \
.filter(ModList.mods.any()) \
Expand All @@ -40,14 +40,14 @@ def packs(gameshort: Optional[str]) -> str:
return render_template("packs.html", ga=game, game=game, packs=packs, page=page, total_pages=total_pages)


@lists.route("/create/pack")
@packs.route("/create/pack")
def create_list() -> str:
games = Game.query.filter(Game.active == True).order_by(desc(Game.id)).all()
ga = Game.query.order_by(desc(Game.id)).first()
return render_template("create_list.html", games=games, ga=ga)
return render_template("pack_create.html", games=games, ga=ga)


@lists.route("/pack/<int:list_id>/delete")
@packs.route("/pack/<int:list_id>/delete")
@loginrequired
@with_session
def delete(list_id: str) -> werkzeug.wrappers.Response:
Expand All @@ -67,26 +67,26 @@ def delete(list_id: str) -> werkzeug.wrappers.Response:
return redirect("/profile/" + current_user.username)


@lists.route("/pack/<list_id>/<list_name>")
@packs.route("/pack/<list_id>/<list_name>")
def view_list(list_id: str, list_name: str) -> str:
mod_list, ga, editable = _get_mod_list(list_id)
return render_template("mod_list.html",
return render_template("pack.html",
**{
'mod_list': mod_list,
'editable': editable,
'ga': ga
})


@lists.route("/pack/<list_id>/<list_name>/edit", methods=['GET', 'POST'])
@packs.route("/pack/<list_id>/<list_name>/edit", methods=['GET', 'POST'])
@with_session
@loginrequired
def edit_list(list_id: str, list_name: str) -> Union[str, werkzeug.wrappers.Response]:
mod_list, ga, editable = _get_mod_list(list_id)
if not editable:
abort(403)
if request.method == 'GET':
return render_template("edit_list.html",
return render_template("pack_edit.html",
**{
'mod_list': mod_list,
'mod_ids': [m.mod.id for m in mod_list.mods],
Expand Down Expand Up @@ -129,4 +129,4 @@ def edit_list(list_id: str, list_name: str) -> Union[str, werkzeug.wrappers.Resp
db.commit()
for mod in mod_list.mods:
mod.sort_index = mods.index(mod.mod.id)
return redirect(url_for("lists.view_list", list_id=mod_list.id, list_name=mod_list.name))
return redirect(url_for("packs.view_list", list_id=mod_list.id, list_name=mod_list.name))
4 changes: 2 additions & 2 deletions KerbalStuff/blueprints/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def view_profile(username: str) -> str:
key=lambda m: m.game.name),
lambda m: m.game.name)))
mods_followed = sorted(profile.following, key=lambda mod: mod.created, reverse=True)
return render_template("view_profile.html",
return render_template("profile.html",
profile=profile, forum_url=forum_url, forum_url_username=forum_url_username,
background=profile.background_url(_cfg('protocol'), _cfg('cdn-domain')),
mods_created=mods_created, mods_followed=mods_followed)
Expand Down Expand Up @@ -100,7 +100,7 @@ def profile(username: str) -> Union[str, werkzeug.wrappers.Response]:
'following': following,
'background': profile.background_url(_cfg('protocol'), _cfg('cdn-domain')),
}
return render_template("profile.html", **parameters)
return render_template("profile_edit.html", **parameters)
else:
profile = User.query.filter(User.username == username).first()
if not profile:
Expand Down
2 changes: 1 addition & 1 deletion KerbalStuff/ckan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def send_to_ckan(mod: Mod) -> None:
'description': mod.description,
'external_link': mod.external_link,
'source_link': mod.source_link,
'user_url': site_base_url + url_for("profile.view_profile", username=mod.user.username),
'user_url': site_base_url + url_for("profile.profile", username=mod.user.username),
'mod_url': site_base_url + url_for('mods.mod', mod_name=mod.name, mod_id=mod.id),
'site_name': site_name,
})
Expand Down
72 changes: 54 additions & 18 deletions frontend/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const sass = require('node-sass');
const browserify = require('browserify');
const coffeeify = require('coffeeify');
const babelify = require('babelify');
const uglifyify = require('uglifyify');
const tildeImporter = require('node-sass-tilde-importer');

const paths = {
Expand All @@ -13,19 +14,35 @@ const paths = {
},
output: {
styles: 'build',
scripts: 'build'
scripts: 'build',
fonts: 'build'
}
};

function walkDir(dir, callback) {
fs.readdirSync(dir).forEach(f => {
let dirPath = path.join(dir, f);
let isDirectory = fs.statSync(dirPath).isDirectory();
isDirectory
? walkDir(dirPath, callback)
: callback(path.join(dir, f));
});
}
const staticDeps = [
[ 'node_modules/bootstrap-table/dist/bootstrap-table.min.css',paths.output.styles ],
[ 'node_modules/chosen-js/chosen.min.css', paths.output.styles ],
[ 'node_modules/@devhau/md-editor/dist/md-editor.min.css', paths.output.styles ],

[ 'node_modules/jquery/dist/jquery.min.js', paths.output.scripts ],
[ 'node_modules/bootstrap-sass/assets/javascripts/bootstrap.min.js', paths.output.scripts ],
[ 'node_modules/bootstrap-table/dist/bootstrap-table.min.js', paths.output.scripts ],
[ 'node_modules/bootstrap-table/dist/extensions/editable/bootstrap-table-editable.min.js', paths.output.scripts ],
[ 'node_modules/bootstrap-table/dist/locale/bootstrap-table-en-US.min.js', paths.output.scripts ],
[ 'node_modules/underscore/underscore-min.js', paths.output.scripts ],
[ 'node_modules/jscroll/dist/jquery.jscroll.min.js', paths.output.scripts ],
[ 'node_modules/chosen-js/chosen.jquery.min.js', paths.output.scripts ],
[ 'node_modules/@devhau/md-editor/dist/md-editor.min.js', paths.output.scripts ],
[ 'node_modules/typeahead.js/dist/typeahead.bundle.min.js', paths.output.scripts ],

[ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.eot', paths.output.fonts ],
[ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.svg', paths.output.fonts ],
[ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf', paths.output.fonts ],
[ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff', paths.output.fonts ],
[ 'node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2', paths.output.fonts ],
[ 'node_modules/font-awesome/fonts/fontawesome-webfont.ttf', paths.output.fonts ],
[ 'node_modules/font-awesome/fonts/fontawesome-webfont.woff2', paths.output.fonts ]
];

for (let path in paths.output) {
if (paths.output.hasOwnProperty(path)) {
Expand All @@ -37,6 +54,24 @@ for (let path in paths.output) {
}
}

for (const [fromFile, toDir] of staticDeps) {
const toFile = fs.statSync(toDir).isDirectory()
? path.join(toDir, path.basename(fromFile))
: toDir;
fs.copyFileSync(fromFile, toFile);
console.log(`Copied ${fromFile} to ${toFile}`);
}

function walkDir(dir, callback) {
fs.readdirSync(dir).forEach(f => {
let dirPath = path.join(dir, f);
let isDirectory = fs.statSync(dirPath).isDirectory();
isDirectory
? walkDir(dirPath, callback)
: callback(path.join(dir, f));
});
}

walkDir(paths.input.styles, inputFile => {
if (!inputFile.endsWith('.scss'))
return;
Expand All @@ -46,19 +81,20 @@ walkDir(paths.input.styles, inputFile => {
sass.render({
file: inputFile,
outfile: outFile,
outputStyle: 'compressed',
importer: tildeImporter,
}, (err, result) => {
if (err)
if (err) {
console.log(err);
else fs.writeFile(outFile,
result.css,
'utf8',
err => {
if (err)
} else {
fs.writeFile(outFile, result.css, 'utf8', err => {
if (err) {
console.log(err);
else
} else {
console.log(`Rendered ${inputFile} to ${outFile}`);
}
});
}
});
});

Expand All @@ -70,7 +106,7 @@ walkDir(paths.input.scripts, inputFile => {
const outFile = path.join(paths.output.scripts, `${basename}.js`);
browserify([inputFile], {
extensions: [ '.js', '.coffee' ],
transform: [ coffeeify, babelify ],
transform: [ coffeeify, babelify, [uglifyify, {global:true}] ],
}).bundle((err, result) => {
if (err) {
console.log(err);
Expand Down
1 change: 0 additions & 1 deletion frontend/coffee/create.manifest

This file was deleted.

1 change: 0 additions & 1 deletion frontend/coffee/edit_mod.manifest

This file was deleted.

22 changes: 22 additions & 0 deletions frontend/coffee/global.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,25 @@ if donation_alert
donation_alert.addEventListener('click', (e) ->
createCookie('dismissed_donation', 'true')
, false)

resize_boxes = () ->
x = $(".modbox, .gamebox").outerWidth()
$(".modbox, .gamebox").css('height', (((x / 16) * 9) + 40) + 'px')

x = $(".packbox").outerWidth()
$(".packbox").css('height', (((x / 16) * 9) + 40) + 'px')

$(document).ready () ->
resize_boxes()
$(window).on('resize', resize_boxes)

$(".changer").mouseover (el, index) ->
$(this).children(".front").hide()
$(this).children(".back").show()

$(".changer").mouseout (el, index) ->
$(this).children(".front").show()
$(this).children(".back").hide()

$("#loginModal").on 'shown.bs.modal', () ->
$("#username").focus()
1 change: 0 additions & 1 deletion frontend/coffee/list.manifest

This file was deleted.

3 changes: 3 additions & 0 deletions frontend/coffee/mods.coffee → frontend/coffee/mod.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
editor = new mdEditor({autoDownloadFontAwesome: false})
editor.render()

window.activateStats()
edit.addEventListener('click', (e) ->
e.preventDefault()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
stats.coffee
mods.coffee
mod.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
editor = new Editor()
editor = new mdEditor({autoDownloadFontAwesome: false})
editor.render()
dropzone = require('dropzone')
dropzone = require('dropzone').Dropzone

error = (name) ->
document.getElementById(name).parentElement.classList.add('has-error')
Expand Down
1 change: 1 addition & 0 deletions frontend/coffee/mod_create.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod_create.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
editor = new Editor()
editor = new mdEditor({autoDownloadFontAwesome: false})
editor.render()

window.upload_bg = (files, box) ->
Expand Down
1 change: 1 addition & 0 deletions frontend/coffee/mod_edit.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod_edit.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
dropzone = require('dropzone')
editor = new mdEditor({autoDownloadFontAwesome: false})
editor.render()
dropzone = require('dropzone').Dropzone

error = (name) ->
document.getElementById(name).parentElement.classList.add('has-error')
Expand Down
1 change: 1 addition & 0 deletions frontend/coffee/mod_update.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod_update.coffee
File renamed without changes.
1 change: 1 addition & 0 deletions frontend/coffee/pack_create.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pack_create.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
editor = new Editor()
editor = new mdEditor({autoDownloadFontAwesome: false})
editor.render()

window.upload_bg = (files, box) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
typeahead.bundle.min.js
edit_pack.coffee
pack_edit.coffee
1 change: 0 additions & 1 deletion frontend/coffee/profile.manifest

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
editor = new Editor()
editor = new mdEditor({autoDownloadFontAwesome: false})
editor.render()

# Background Uploading
Expand Down
1 change: 1 addition & 0 deletions frontend/coffee/profile_edit.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
profile_edit.coffee
Loading