blob: c5073ef4d360cbac3f49e5a1542976d170a307f5 [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
Nils Diewalde2c83812014-11-11 21:13:18 +00003use Mojo::ByteStream 'b';
Nils Diewald5d1ffb42014-05-21 17:45:34 +00004
Nils Diewald80d4c6e2014-11-19 02:53:16 +00005our $VERSION = '0.08';
Nils Diewald7cad8402014-07-08 17:06:56 +00006
7# Start dev with
Nils Diewaldf7366232014-07-25 15:57:08 +00008# morbo -w lib -w templates -w public/sass -w public/js -w public/css script/korap
Nils Diewaldeca30442014-11-18 20:33:54 +00009# morbo -m test -w lib -w templates -w public/sass -w public/js -w public/css script/korap
Nils Diewaldf7366232014-07-25 15:57:08 +000010
Nils Diewald002e8fb2014-06-22 14:27:01 +000011# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000012sub startup {
13 my $self = shift;
14
Nils Diewald7cad8402014-07-08 17:06:56 +000015 $self->defaults(layout => 'default');
16
Nils Diewald002e8fb2014-06-22 14:27:01 +000017 # Set secret for signed cookies
Nils Diewald33e15552014-06-13 19:38:37 +000018 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
19
Nils Diewald002e8fb2014-06-22 14:27:01 +000020 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000021 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000022
23 # Load plugins
24 foreach (qw/Config
25 CHI
26 TagHelpers::Pagination
27 Notifications
28 Number::Commify
29 KorapSearch
30 KorapInfo
Nils Diewald7cad8402014-07-08 17:06:56 +000031 KorapTagHelpers
Nils Diewald94bae912014-09-22 13:40:31 +000032 /) {
33 # Oro::Account
34 # Oro::Account::ConfirmMail
Nils Diewald002e8fb2014-06-22 14:27:01 +000035 $self->plugin($_);
36 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000037
Nils Diewald94bae912014-09-22 13:40:31 +000038 $self->plugin(AssetPack => { minify => 1 });
Nils Diewald7cad8402014-07-08 17:06:56 +000039 $self->plugin('AssetPack::LibSass');
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000040 $self->plugin('MailException' => $self->config('MailException'));
Nils Diewald7cad8402014-07-08 17:06:56 +000041
Nils Diewald94bae912014-09-22 13:40:31 +000042 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000043 $self->asset(
44 'korap.css' => (
45 '/sass/style.scss',
46 '/sass/sidebar.scss',
47 '/sass/tutorial.scss',
48 '/sass/hint.scss',
49 '/sass/query.scss',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000050 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000051 '/sass/pagination.scss',
52 '/sass/kwic-4.0.scss',
53 '/css/media.css',
54 '/css/font-awesome.min.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000055 '/css/highlight.css',
Nils Diewald063a7c42014-11-12 20:11:55 +000056 '/sass/alertify.scss',
Nils Diewaldca01b762014-09-08 02:35:20 +000057 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000058 )
59 );
60
61 $self->asset(
62 'korap.js' => (
Nils Diewaldf2e02a92014-11-12 18:31:05 +000063# '/js/d3.v3.min.js',
64# '/js/dagre-d3.min.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000065 '/js/jquery-2.0.0.min.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000066 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000067 '/js/translateTable.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000068# '/js/translateTree.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000069 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000070 '/js/highlight.pack.js',
71 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000072 )
73 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000074
Nils Diewald2329e1d2014-06-12 16:07:57 +000075 $self->helper(
76 date_format => sub {
77 my ($c, $date) = @_;
78 return $date;
79 }
80 );
81
Nils Diewald64bab252014-05-22 11:04:04 +000082 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000083 my $r = $self->routes;
84
Nils Diewald94bae912014-09-22 13:40:31 +000085 # User account management
86 # $r->route('/login')->acct('login');
87 # $r->route('/login/forgotten')->acct('forgotten');
88 # $r->route('/login/remove')->acct('remove');
89 # $r->route('/register')->acct('register');
90 # $r->route('/logout')->acct('logout');
91 # $r->route('/preferences')->acct('preferences');
92
Nils Diewald002e8fb2014-06-22 14:27:01 +000093 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000094 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000095
Nils Diewald002e8fb2014-06-22 14:27:01 +000096 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000097 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
98 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000099
Nils Diewald002e8fb2014-06-22 14:27:01 +0000100 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +0000101 my $collection = $r->bridge('/collection');
102 $collection->to('info#about_collection');
103 my $collection_id = $collection->bridge('/:collection_id');
104 # stats
105 # $collection_id->;
106 $collection_id->search;
Nils Diewald1eba6572014-06-17 19:49:53 +0000107
Nils Diewald002e8fb2014-06-22 14:27:01 +0000108 # Corpus data
Nils Diewald7cad8402014-07-08 17:06:56 +0000109 my $corpus_res = $r->route('/corpus');
110 my $corpus = $corpus_res->route('/:corpus_id');
111 # Todo: Stats
112 $corpus->search->name('search_corpus');
113 my $doc = $corpus->route('/#doc_id');
114 $doc->search->name('search_document');
115
116 # Match data
117 my $match = $doc->route('/:match_id');
118 $match->route->to('info#about_match')->name('match');
Nils Diewaldf2e02a92014-11-12 18:31:05 +0000119# my $match_foundry = $match->route('/:foundry');
120# $match_foundry->route->to('info#about_match');
121# $match_foundry->route('/:layer')->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +0000122
Nils Diewald002e8fb2014-06-22 14:27:01 +0000123 # Utilities
Nils Diewald7cad8402014-07-08 17:06:56 +0000124 # $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +0000125};
126
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000127
1281;