blob: 05135f2919ffba10f8329ac08d64a878d3207040 [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
Nils Diewald996aa552014-12-02 03:26:44 +000029 Search
Nils Diewald002e8fb2014-06-22 14:27:01 +000030 KorapInfo
Nils Diewald996aa552014-12-02 03:26:44 +000031 KorapHelpers
Nils Diewald7cad8402014-07-08 17:06:56 +000032 KorapTagHelpers
Nils Diewald94bae912014-09-22 13:40:31 +000033 /) {
34 # Oro::Account
35 # Oro::Account::ConfirmMail
Nils Diewald002e8fb2014-06-22 14:27:01 +000036 $self->plugin($_);
37 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000038
Nils Diewald996aa552014-12-02 03:26:44 +000039# $self->plugin(AssetPack => { minify => 1 });
40 $self->plugin('AssetPack');
Nils Diewald7cad8402014-07-08 17:06:56 +000041 $self->plugin('AssetPack::LibSass');
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000042 $self->plugin('MailException' => $self->config('MailException'));
Nils Diewald7cad8402014-07-08 17:06:56 +000043
Nils Diewald94bae912014-09-22 13:40:31 +000044 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000045 $self->asset(
46 'korap.css' => (
47 '/sass/style.scss',
48 '/sass/sidebar.scss',
49 '/sass/tutorial.scss',
50 '/sass/hint.scss',
51 '/sass/query.scss',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000052 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000053 '/sass/pagination.scss',
54 '/sass/kwic-4.0.scss',
55 '/css/media.css',
56 '/css/font-awesome.min.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000057 '/css/highlight.css',
Nils Diewald063a7c42014-11-12 20:11:55 +000058 '/sass/alertify.scss',
Nils Diewaldca01b762014-09-08 02:35:20 +000059 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000060 )
61 );
62
63 $self->asset(
64 'korap.js' => (
Nils Diewald996aa552014-12-02 03:26:44 +000065 '/js/d3.v3.min.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000066# '/js/dagre-d3.min.js',
Nils Diewald996aa552014-12-02 03:26:44 +000067 '/js/dagre-d3.js',
68 '/js/translateTree.js',
69 '/js/jquery-2.0.0.min.js', # Temp
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000070 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000071 '/js/translateTable.js',
72 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000073 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +000074 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000075 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000076 )
77 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000078
Nils Diewald2329e1d2014-06-12 16:07:57 +000079 $self->helper(
80 date_format => sub {
81 my ($c, $date) = @_;
82 return $date;
83 }
84 );
85
Nils Diewald64bab252014-05-22 11:04:04 +000086 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000087 my $r = $self->routes;
88
Nils Diewald94bae912014-09-22 13:40:31 +000089 # User account management
90 # $r->route('/login')->acct('login');
91 # $r->route('/login/forgotten')->acct('forgotten');
92 # $r->route('/login/remove')->acct('remove');
93 # $r->route('/register')->acct('register');
94 # $r->route('/logout')->acct('logout');
95 # $r->route('/preferences')->acct('preferences');
96
Nils Diewald002e8fb2014-06-22 14:27:01 +000097 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000098 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000099
Nils Diewald002e8fb2014-06-22 14:27:01 +0000100 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +0000101 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
102 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +0000103
Nils Diewald002e8fb2014-06-22 14:27:01 +0000104 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +0000105 my $collection = $r->bridge('/collection');
106 $collection->to('info#about_collection');
107 my $collection_id = $collection->bridge('/:collection_id');
108 # stats
Nils Diewald996aa552014-12-02 03:26:44 +0000109};
110
111
1121;
113
114
115__END__
116
117
118
119# No shortcut!
120
121# $collection_id->search;
Nils Diewald1eba6572014-06-17 19:49:53 +0000122
Nils Diewald002e8fb2014-06-22 14:27:01 +0000123 # Corpus data
Nils Diewald7cad8402014-07-08 17:06:56 +0000124 my $corpus_res = $r->route('/corpus');
125 my $corpus = $corpus_res->route('/:corpus_id');
Nils Diewald996aa552014-12-02 03:26:44 +0000126
Nils Diewald7cad8402014-07-08 17:06:56 +0000127 # Todo: Stats
Nils Diewald996aa552014-12-02 03:26:44 +0000128# $corpus->search->name('search_corpus');
129# my $doc = $corpus->route('/#doc_id');
130# $doc->search->name('search_document');
Nils Diewald7cad8402014-07-08 17:06:56 +0000131
132 # Match data
133 my $match = $doc->route('/:match_id');
134 $match->route->to('info#about_match')->name('match');
Nils Diewalde99d9042014-11-20 23:36:54 +0000135 # my $match_foundry = $match->route('/:foundry');
136 # $match_foundry->route->to('info#about_match');
137 # $match_foundry->route('/:layer')->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +0000138
Nils Diewald002e8fb2014-06-22 14:27:01 +0000139 # Utilities
Nils Diewald7cad8402014-07-08 17:06:56 +0000140 # $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +0000141};
142
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000143
1441;