2015-10-25 06:17:45 +01:00
|
|
|
# Pony.fm - A community for pony fan music.
|
|
|
|
# Copyright (C) 2015 Peter Deltchev
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-02-14 17:14:30 +01:00
|
|
|
|
2016-02-14 18:27:57 +01:00
|
|
|
# Some notes on what's going on here:
|
|
|
|
#
|
|
|
|
# - Webpack resolves all of these require statements.
|
|
|
|
#
|
|
|
|
# - jQuery is loaded before Angular so it replaces jqLite.
|
|
|
|
#
|
|
|
|
# - "script!" is used with dependencies that expect to interact with the global state.
|
|
|
|
#
|
|
|
|
# - The "ponyfm" module in this file must be initialized before the controllers
|
|
|
|
# and other Angular modules are brought in; they expect the "ponyfm" module to exist.
|
|
|
|
|
2016-02-14 17:14:30 +01:00
|
|
|
require 'script!../base/jquery-2.0.2'
|
|
|
|
angular = require 'angular'
|
|
|
|
|
2016-03-16 02:59:46 +01:00
|
|
|
require 'angular-ui-router'
|
2016-08-03 02:37:23 +02:00
|
|
|
require 'angular-material'
|
2016-02-14 17:14:30 +01:00
|
|
|
require '../base/angular-ui-sortable'
|
|
|
|
require '../base/angularytics'
|
|
|
|
require '../base/jquery.cookie'
|
|
|
|
require '../base/jquery.timeago'
|
|
|
|
require 'script!../base/marked'
|
|
|
|
require 'script!../base/moment'
|
|
|
|
require '../base/soundmanager2-nodebug'
|
2016-07-17 02:22:59 +02:00
|
|
|
require 'color-thief';
|
2016-05-21 22:34:12 +02:00
|
|
|
require 'angular-strap'
|
2016-05-21 23:15:37 +02:00
|
|
|
# Just ignore this, blame webpack
|
|
|
|
require '../../../../node_modules/angular-strap/dist/angular-strap.tpl'
|
2016-05-04 18:07:14 +02:00
|
|
|
require 'chart.js';
|
|
|
|
require 'angular-chart.js';
|
2016-02-14 17:14:30 +01:00
|
|
|
|
|
|
|
require '../shared/pfm-angular-marked'
|
|
|
|
require '../shared/pfm-angular-sanitize'
|
2016-02-16 12:26:05 +01:00
|
|
|
require '../shared/init.coffee'
|
2016-02-14 17:14:30 +01:00
|
|
|
|
|
|
|
|
2016-08-03 02:37:23 +02:00
|
|
|
ponyfm = angular.module 'ponyfm', ['ngMaterial', 'mgcrea.ngStrap', 'ui.router', 'ui.sortable', 'angularytics', 'ngSanitize', 'hc.marked', 'chart.js']
|
2015-08-31 17:42:21 +02:00
|
|
|
window.pfm.preloaders = {}
|
|
|
|
|
2016-02-14 18:27:57 +01:00
|
|
|
# Inspired by: https://stackoverflow.com/a/30652110/3225811
|
|
|
|
requireDirectory = (r) ->
|
2016-02-14 17:14:30 +01:00
|
|
|
r.keys().forEach(r)
|
|
|
|
|
2016-02-14 18:27:57 +01:00
|
|
|
requireDirectory(require.context('./controllers/', false, /\.coffee$/));
|
|
|
|
requireDirectory(require.context('./directives/', false, /\.coffee$/));
|
|
|
|
requireDirectory(require.context('./filters/', false, /\.coffee$/));
|
|
|
|
requireDirectory(require.context('./services/', false, /\.coffee$/));
|
2016-02-14 17:14:30 +01:00
|
|
|
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-24 04:44:20 +02:00
|
|
|
if window.pfm.environment == 'production'
|
2016-02-14 17:14:30 +01:00
|
|
|
ponyfm.run [
|
2015-10-25 03:35:37 +01:00
|
|
|
'Angularytics',
|
|
|
|
(analytics) ->
|
|
|
|
analytics.init()
|
|
|
|
]
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2016-02-14 17:14:30 +01:00
|
|
|
ponyfm.run [
|
2016-03-16 05:37:17 +01:00
|
|
|
'$rootScope', 'meta',
|
|
|
|
($rootScope, meta) ->
|
2015-12-17 01:14:46 +01:00
|
|
|
$rootScope.$on '$stateChangeStart', (event, toState, toParams, fromState, fromParams) ->
|
2016-03-16 05:37:17 +01:00
|
|
|
meta.reset()
|
2015-12-17 01:14:46 +01:00
|
|
|
]
|
|
|
|
|
2016-02-14 17:14:30 +01:00
|
|
|
ponyfm.config [
|
2016-08-03 02:37:23 +02:00
|
|
|
'$locationProvider', '$stateProvider', 'AngularyticsProvider', '$httpProvider', '$sceDelegateProvider', 'markedProvider', '$mdDateLocaleProvider', '$mdThemingProvider'
|
|
|
|
(location, state, analytics, $httpProvider, $sceDelegateProvider, markedProvider, $mdDateLocaleProvider, $mdThemingProvider) ->
|
2015-10-25 03:35:37 +01:00
|
|
|
|
2015-12-16 14:07:03 +01:00
|
|
|
if window.pfm.environment == 'local'
|
|
|
|
$httpProvider.interceptors.push [
|
|
|
|
->
|
|
|
|
request: (config) ->
|
|
|
|
return config if !(/^\/?templates\//.test config.url)
|
|
|
|
config.url += '?' + Math.ceil(Math.random() * 1000000)
|
|
|
|
return config
|
|
|
|
]
|
2015-10-25 03:35:37 +01:00
|
|
|
|
|
|
|
# This fixes resource loading on IE
|
|
|
|
$sceDelegateProvider.resourceUrlWhitelist [
|
|
|
|
'self',
|
2016-02-14 11:53:27 +01:00
|
|
|
'/templates/directives/*',
|
|
|
|
# Used for the "Tweet" button on content item pages
|
|
|
|
'https://platform.twitter.com/widgets/tweet_button.html**'
|
2015-10-25 03:35:37 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
if window.pfm.environment == 'production'
|
|
|
|
analytics.setEventHandlers ['Google']
|
|
|
|
|
2015-12-27 16:59:38 +01:00
|
|
|
markedProvider.setOptions
|
|
|
|
gfm: true
|
2015-12-27 18:04:17 +01:00
|
|
|
tables: false
|
2015-12-27 16:59:38 +01:00
|
|
|
sanitize: true
|
|
|
|
smartLists: true
|
|
|
|
smartypants: true
|
2015-12-27 19:15:22 +01:00
|
|
|
breaks: true
|
2015-12-27 16:59:38 +01:00
|
|
|
|
2015-12-27 18:04:17 +01:00
|
|
|
|
|
|
|
markedProvider.setRenderer
|
|
|
|
link: (href, title, text) ->
|
2015-12-27 18:55:42 +01:00
|
|
|
'<a href="' + href + '" target="_blank" rel="nofollow">' + href + '</a>'
|
2015-12-27 18:04:17 +01:00
|
|
|
heading: (text, level) ->
|
|
|
|
text
|
|
|
|
image: (url) ->
|
|
|
|
url
|
2015-12-27 18:55:42 +01:00
|
|
|
codespan: (code) ->
|
|
|
|
code
|
|
|
|
code: (code, language) ->
|
|
|
|
code
|
|
|
|
del: (text) ->
|
|
|
|
text
|
|
|
|
|
2016-08-03 02:37:23 +02:00
|
|
|
$mdDateLocaleProvider.formatDate = (date) ->
|
|
|
|
return moment(date).format('DD/MM/YYYY')
|
|
|
|
|
|
|
|
$mdDateLocaleProvider.parseDate = (string) ->
|
|
|
|
return moment(date).format('DD/MM/YYYY')
|
|
|
|
|
|
|
|
pfmPurple = $mdThemingProvider.extendPalette('purple', {
|
|
|
|
'50': '#f5eff6',
|
|
|
|
'100': '#d6bfd9',
|
|
|
|
'200': '#c09cc4',
|
|
|
|
'300': '#a36faa',
|
|
|
|
'400': '#965d9d',
|
|
|
|
'500': '#84528a',
|
|
|
|
'600': '#724777',
|
|
|
|
'700': '#5f3b64',
|
|
|
|
'800': '#4d3050',
|
|
|
|
'900': '#3b243d',
|
|
|
|
'A100': '#c09cc4',
|
|
|
|
'A200': '#965d9d',
|
|
|
|
'A400': '#724777',
|
|
|
|
'A700': '#65326b',
|
|
|
|
'contrastDefaultColor': 'light',
|
|
|
|
'contrastDarkColors': '50 100 200 300 A100'
|
|
|
|
})
|
|
|
|
|
|
|
|
$mdThemingProvider.definePalette('pfmPurple', pfmPurple)
|
|
|
|
|
|
|
|
$mdThemingProvider.theme('default')
|
|
|
|
.primaryPalette('pfmPurple')
|
|
|
|
.accentPalette('pfmPurple')
|
|
|
|
.warnPalette('red')
|
2015-12-27 16:59:38 +01:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
# Errors
|
|
|
|
state.state 'errors-404',
|
|
|
|
url: '/errors/not-found'
|
|
|
|
templateUrl: '/templates/errors/404.html'
|
|
|
|
|
|
|
|
state.state 'errors-500',
|
|
|
|
url: '/errors/server'
|
|
|
|
templateUrl: '/templates/errors/500.html'
|
|
|
|
|
|
|
|
state.state 'errors-403',
|
|
|
|
url: '/errors/not-authorized'
|
|
|
|
templateUrl: '/templates/errors/403.html'
|
|
|
|
|
|
|
|
state.state 'errors-400',
|
|
|
|
url: '/errors/invalid'
|
|
|
|
templateUrl: '/templates/errors/400.html'
|
|
|
|
|
|
|
|
# Tracks
|
|
|
|
|
|
|
|
state.state 'content',
|
|
|
|
abstract: true
|
2016-01-07 08:46:39 +01:00
|
|
|
template: '<ui-view/>'
|
2015-10-25 03:35:37 +01:00
|
|
|
|
|
|
|
state.state 'content.tracks',
|
|
|
|
templateUrl: '/templates/tracks/index.html'
|
|
|
|
controller: 'tracks'
|
|
|
|
url: '/tracks'
|
|
|
|
abstract: true
|
|
|
|
|
|
|
|
state.state 'content.tracks.list',
|
|
|
|
url: '^/tracks?filter&page'
|
|
|
|
templateUrl: '/templates/tracks/list.html'
|
|
|
|
controller: 'tracks-list'
|
|
|
|
|
|
|
|
state.state 'content.track',
|
|
|
|
url: '/tracks/{id:[^\-]+}-{slug}'
|
2015-08-15 06:20:05 +02:00
|
|
|
templateUrl: '/templates/tracks/frame.html'
|
2015-10-25 03:35:37 +01:00
|
|
|
controller: 'track'
|
2015-08-15 06:20:05 +02:00
|
|
|
abstract: true
|
|
|
|
|
|
|
|
state.state 'content.track.show',
|
|
|
|
url: ''
|
|
|
|
templateUrl: '/templates/tracks/show.html'
|
|
|
|
controller: 'track-show'
|
|
|
|
|
|
|
|
state.state 'content.track.edit',
|
|
|
|
url: '/edit'
|
|
|
|
templateUrl: '/templates/tracks/edit.html'
|
|
|
|
controller: 'track-edit'
|
|
|
|
|
2016-05-03 00:25:54 +02:00
|
|
|
state.state 'content.track.stats',
|
|
|
|
url: '/stats'
|
|
|
|
templateUrl: '/templates/tracks/stats.html'
|
|
|
|
controller: 'track-stats'
|
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
|
|
|
|
# Albums
|
|
|
|
|
|
|
|
state.state 'content.albums',
|
|
|
|
url: '/albums'
|
|
|
|
templateUrl: '/templates/albums/index.html'
|
|
|
|
controller: 'albums'
|
|
|
|
abstract: true
|
|
|
|
|
|
|
|
state.state 'content.albums.list',
|
|
|
|
url: '?page'
|
|
|
|
templateUrl: '/templates/albums/list.html'
|
|
|
|
controller: 'albums-list'
|
|
|
|
|
|
|
|
state.state 'content.album',
|
|
|
|
url: '/albums/{id:[^\-]+}-{slug}'
|
|
|
|
templateUrl: '/templates/albums/show.html'
|
|
|
|
controller: 'album'
|
|
|
|
|
|
|
|
# Playlists
|
|
|
|
|
|
|
|
state.state 'content.playlists',
|
|
|
|
url: '/playlists'
|
|
|
|
templateUrl: '/templates/playlists/index.html'
|
|
|
|
controller: 'playlists'
|
|
|
|
abstract: true
|
|
|
|
|
|
|
|
state.state 'content.playlists.list',
|
2016-06-01 21:02:16 +02:00
|
|
|
url: '^/playlists?filter&page'
|
2015-10-25 03:35:37 +01:00
|
|
|
controller: 'playlists-list'
|
|
|
|
templateUrl: '/templates/playlists/list.html'
|
|
|
|
|
|
|
|
state.state 'content.playlist',
|
|
|
|
url: '/playlist/{id:[^\-]+}-{slug}'
|
|
|
|
templateUrl: '/templates/playlists/show.html'
|
|
|
|
controller: 'playlist'
|
|
|
|
|
|
|
|
# Artists
|
|
|
|
|
|
|
|
state.state 'content.artists',
|
|
|
|
url: '/artists'
|
|
|
|
templateUrl: '/templates/artists/index.html'
|
|
|
|
controller: 'artists'
|
|
|
|
abstract: true
|
|
|
|
|
|
|
|
state.state 'content.artists.list',
|
|
|
|
url: '?page'
|
|
|
|
templateUrl: '/templates/artists/list.html'
|
|
|
|
controller: 'artists-list'
|
|
|
|
|
|
|
|
# Pages
|
|
|
|
|
2015-12-06 09:22:00 +01:00
|
|
|
state.state 'pages',
|
|
|
|
templateUrl: '/templates/pages/_layout.html'
|
2015-10-25 03:35:37 +01:00
|
|
|
|
2015-12-06 09:22:00 +01:00
|
|
|
state.state 'pages.about',
|
2015-10-25 03:35:37 +01:00
|
|
|
url: '/about'
|
|
|
|
templateUrl: '/templates/pages/about.html'
|
|
|
|
|
2015-12-06 09:22:00 +01:00
|
|
|
state.state 'pages.faq',
|
|
|
|
url: '/faq'
|
|
|
|
templateUrl: '/templates/pages/faq.html'
|
|
|
|
|
|
|
|
state.state 'pages.mlpforums-advertising-program',
|
|
|
|
url: '/mlpforums-advertising-program'
|
|
|
|
templateUrl: '/templates/pages/mlpforums-advertising-program.html'
|
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
# Auth
|
|
|
|
|
|
|
|
state.state 'login',
|
|
|
|
url: '/login'
|
|
|
|
templateUrl: '/templates/auth/login.html'
|
|
|
|
controller: 'login'
|
|
|
|
|
|
|
|
state.state 'register',
|
|
|
|
url: '/register'
|
|
|
|
templateUrl: '/templates/auth/register.html'
|
|
|
|
|
2015-11-24 06:19:23 +01:00
|
|
|
# Admin
|
|
|
|
|
|
|
|
state.state 'admin',
|
|
|
|
abstract: true
|
|
|
|
url: '/admin'
|
|
|
|
templateUrl: '/templates/admin/_layout.html'
|
|
|
|
|
|
|
|
state.state 'admin.genres',
|
2015-11-24 11:49:47 +01:00
|
|
|
url: '/genres'
|
|
|
|
controller: 'admin-genres'
|
2015-11-24 06:19:23 +01:00
|
|
|
templateUrl: '/templates/admin/genres.html'
|
|
|
|
|
2016-06-06 01:12:04 +02:00
|
|
|
state.state 'admin.showsongs',
|
|
|
|
url: '/show-songs'
|
|
|
|
controller: 'admin-show-songs'
|
|
|
|
templateUrl: '/templates/admin/show-songs.html'
|
|
|
|
|
2016-05-11 18:41:49 +02:00
|
|
|
state.state 'admin.tracks',
|
|
|
|
url: '/tracks'
|
|
|
|
controller: 'admin-tracks'
|
|
|
|
templateUrl: '/templates/admin/tracks.html'
|
|
|
|
|
2016-06-12 07:55:27 +02:00
|
|
|
state.state 'admin.users',
|
|
|
|
url: '/users'
|
|
|
|
controller: 'admin-users'
|
|
|
|
templateUrl: '/templates/admin/users.html'
|
|
|
|
|
2015-11-24 06:19:23 +01:00
|
|
|
# Homepage
|
2015-10-25 03:35:37 +01:00
|
|
|
|
|
|
|
if window.pfm.auth.isLogged
|
|
|
|
state.state 'home',
|
|
|
|
url: '/'
|
|
|
|
templateUrl: '/templates/dashboard/index.html'
|
|
|
|
controller: 'dashboard'
|
2016-05-27 21:12:40 +02:00
|
|
|
|
|
|
|
state.state 'notifications',
|
|
|
|
url: '/notifications'
|
|
|
|
templateUrl: '/templates/notifications/index.html'
|
|
|
|
controller: 'notifications'
|
2015-10-25 03:35:37 +01:00
|
|
|
else
|
|
|
|
state.state 'home',
|
|
|
|
url: '/'
|
|
|
|
templateUrl: '/templates/home/index.html'
|
|
|
|
controller: 'home'
|
|
|
|
|
2016-03-16 17:32:39 +01:00
|
|
|
# Final catch-all for artists
|
2015-10-25 03:35:37 +01:00
|
|
|
state.state 'content.artist',
|
|
|
|
url: '^/{slug}'
|
|
|
|
templateUrl: '/templates/artists/_show_layout.html'
|
|
|
|
abstract: true
|
|
|
|
controller: 'artist'
|
|
|
|
|
|
|
|
state.state 'content.artist.profile',
|
2016-05-16 16:00:28 +02:00
|
|
|
url: '^/{slug}'
|
2015-10-25 03:35:37 +01:00
|
|
|
templateUrl: '/templates/artists/profile.html'
|
|
|
|
controller: 'artist-profile'
|
|
|
|
|
|
|
|
state.state 'content.artist.content',
|
|
|
|
url: '/content'
|
|
|
|
templateUrl: '/templates/artists/content.html'
|
|
|
|
controller: 'artist-content'
|
|
|
|
|
|
|
|
state.state 'content.artist.favourites',
|
|
|
|
url: '/favourites'
|
|
|
|
templateUrl: '/templates/artists/favourites.html'
|
|
|
|
controller: 'artist-favourites'
|
|
|
|
|
2016-03-18 12:22:54 +01:00
|
|
|
|
|
|
|
# Account
|
|
|
|
|
|
|
|
state.state 'content.artist.account',
|
|
|
|
url: '/account'
|
|
|
|
abstract: true
|
|
|
|
templateUrl: '/templates/account/_layout.html'
|
|
|
|
|
2016-03-19 03:47:45 +01:00
|
|
|
# Upload
|
|
|
|
|
|
|
|
state.state 'content.artist.account.uploader',
|
|
|
|
url: '/uploader'
|
|
|
|
templateUrl: '/templates/uploader/index.html'
|
|
|
|
controller: 'uploader'
|
|
|
|
|
2016-03-18 12:22:54 +01:00
|
|
|
state.state 'content.artist.account.settings',
|
|
|
|
url: ''
|
|
|
|
templateUrl: '/templates/account/settings.html'
|
|
|
|
controller: 'account-settings'
|
|
|
|
|
|
|
|
state.state 'content.artist.account.tracks',
|
|
|
|
url: '/tracks'
|
|
|
|
templateUrl: '/templates/account/tracks.html'
|
|
|
|
controller: 'account-tracks'
|
|
|
|
|
|
|
|
state.state 'content.artist.account.tracks.edit',
|
|
|
|
url: '/edit/:track_id'
|
|
|
|
templateUrl: '/templates/account/track.html'
|
|
|
|
controller: 'account-track'
|
|
|
|
|
|
|
|
state.state 'content.artist.account.albums',
|
|
|
|
url: '/albums'
|
|
|
|
templateUrl: '/templates/account/albums.html'
|
|
|
|
controller: 'account-albums'
|
|
|
|
|
|
|
|
state.state 'content.artist.account.albums.create',
|
|
|
|
url: '/create'
|
|
|
|
templateUrl: '/templates/account/album.html'
|
|
|
|
controller: 'account-albums-edit'
|
|
|
|
|
|
|
|
state.state 'content.artist.account.albums.edit',
|
|
|
|
url: '/edit/:album_id'
|
|
|
|
templateUrl: '/templates/account/album.html'
|
|
|
|
controller: 'account-albums-edit'
|
|
|
|
|
|
|
|
state.state 'content.artist.account.playlists',
|
|
|
|
url: '/playlists'
|
|
|
|
templateUrl: '/templates/account/playlists.html'
|
|
|
|
controller: 'account-playlists'
|
|
|
|
|
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
location.html5Mode(true);
|
2015-12-17 01:14:46 +01:00
|
|
|
|
2015-10-24 04:44:20 +02:00
|
|
|
]
|
2016-02-14 17:14:30 +01:00
|
|
|
|
|
|
|
module.exports = ponyfm
|