blob: 49922b27e6d8de177e85dac361a2443d007d01c5 [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 Diewalde99d9042014-11-20 23:36:54 +000065# '/js/translateTree.js',
66# '/js/jquery-2.0.0.min.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000067 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000068 '/js/translateTable.js',
69 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000070 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +000071 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000072 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000073 )
74 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000075
Nils Diewald2329e1d2014-06-12 16:07:57 +000076 $self->helper(
77 date_format => sub {
78 my ($c, $date) = @_;
79 return $date;
80 }
81 );
82
Nils Diewald64bab252014-05-22 11:04:04 +000083 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000084 my $r = $self->routes;
85
Nils Diewald94bae912014-09-22 13:40:31 +000086 # User account management
87 # $r->route('/login')->acct('login');
88 # $r->route('/login/forgotten')->acct('forgotten');
89 # $r->route('/login/remove')->acct('remove');
90 # $r->route('/register')->acct('register');
91 # $r->route('/logout')->acct('logout');
92 # $r->route('/preferences')->acct('preferences');
93
Nils Diewald002e8fb2014-06-22 14:27:01 +000094 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000095 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000096
Nils Diewald002e8fb2014-06-22 14:27:01 +000097 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000098 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
99 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +0000100
Nils Diewald002e8fb2014-06-22 14:27:01 +0000101 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +0000102 my $collection = $r->bridge('/collection');
103 $collection->to('info#about_collection');
104 my $collection_id = $collection->bridge('/:collection_id');
105 # stats
Nils Diewald7cad8402014-07-08 17:06:56 +0000106 $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 Diewalde99d9042014-11-20 23:36:54 +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;