Verified Commit f26363c0 authored by Luc Didry's avatar Luc Didry

Fix #38 Import URL by JSON upload

parent c1d41128
Pipeline #49972 passed with stages
in 6 minutes and 30 seconds
......@@ -18,7 +18,7 @@ push-locales:
zanata-cli -q -B push
pull-locales:
zanata-cli -q -B pull
zanata-cli -q -B pull --min-doc-percent 40
stats-locales:
zanata-cli -q stats
......
......@@ -382,6 +382,14 @@ sub startup {
->to('Lstu#add')
->name('add');
$r->get('/cookie')
->to('Lstu#export_cookie')
->name('export_cookie');
$r->post('/cookie')
->to('Lstu#import_cookie')
->name('import_cookie');
$r->get('/stats')
->to('Lstu#stats')
->name('stats');
......
......@@ -120,7 +120,13 @@ sub add {
@{$u} = keys %k;
# And set the cookie
my $cookie = to_json($u);
$c->cookie('url' => $cookie, {expires => time + 142560000}); # expires in 10 years
$c->cookie(
'url' => $cookie,
{
path => $c->config('prefix'),
expires => time + 142560000
}
); # expires in 10 years
my $prefix = $c->prefix;
......@@ -144,6 +150,46 @@ sub add {
}
}
sub export_cookie {
my $c = shift;
my $u = (defined($c->cookie('url'))) ? decode_json $c->cookie('url') : [];
$c->res->headers->add('Content-Disposition' => 'attachment;filename=lstu_export.json');
return $c->render(json => $u);
}
sub import_cookie {
my $c = shift;
my $file = $c->param('file');
my $json = decode_json($file->slurp);
if (ref($json) eq 'ARRAY') {
# Get URLs from cookie
my $u = (defined($c->cookie('url'))) ? decode_json $c->cookie('url') : [];
# Add the new URL
push @{$u}, @{$json};
# Make the array contain only unique URLs
my %k = map { $_, 1 } @{$u};
@{$u} = keys %k;
# And set the cookie
my $cookie = to_json($u);
$c->cookie(
'url' => $cookie,
{
path => $c->config('prefix'),
expires => time + 142560000
}
); # expires in 10 years
$c->flash(success_msg => $c->l('File imported'));
} else {
$c->flash(msg => $c->l('Sorry, unable to parse the provided file'));
}
return $c->redirect_to('stats');
}
sub fullstats {
my $c = shift;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -24,7 +24,7 @@ msgstr ""
msgid "A page with a table containing the same informations that the JSON response"
msgstr ""
#: themes/default/templates/layouts/default.html.ep:32
#: themes/default/templates/layouts/default.html.ep:38
msgid "About"
msgstr ""
......@@ -36,7 +36,7 @@ msgstr ""
msgid "Bad password"
msgstr ""
#: themes/default/templates/layouts/default.html.ep:44
#: themes/default/templates/layouts/default.html.ep:50
msgid "Browser extensions"
msgstr ""
......@@ -44,11 +44,11 @@ msgstr ""
msgid "Copy to clipboard"
msgstr ""
#: themes/default/templates/stats.html.ep:31
#: themes/default/templates/stats.html.ep:46
msgid "Counter"
msgstr ""
#: themes/default/templates/stats.html.ep:32
#: themes/default/templates/stats.html.ep:47
msgid "Created"
msgstr ""
......@@ -56,14 +56,22 @@ msgstr ""
msgid "Custom shortened text"
msgstr ""
#: themes/default/templates/stats.html.ep:37
#: themes/default/templates/stats.html.ep:52
msgid "Delete"
msgstr ""
#: themes/default/templates/stats.html.ep:36
msgid "Export your URLs"
msgstr ""
#: themes/default/templates/api.html.ep:105 themes/default/templates/api.html.ep:145 themes/default/templates/api.html.ep:53 themes/default/templates/api.html.ep:71
msgid "Failure reason"
msgstr ""
#: lib/Lstu/Controller/Lstu.pm:186
msgid "File imported"
msgstr ""
#: themes/default/templates/api.html.ep:101
msgid "Get the details (visit counter, creation date, etc.) of a shortened URL."
msgstr ""
......@@ -84,7 +92,7 @@ msgstr ""
msgid "Hit Enter, then Ctrl+C to copy the short link"
msgstr ""
#: themes/default/templates/stats.html.ep:74
#: themes/default/templates/stats.html.ep:89
msgid "Home"
msgstr ""
......@@ -109,6 +117,10 @@ msgstr ""
msgid "If you are logged in as admin, you can provide a \"page\" parameter"
msgstr ""
#: themes/default/templates/stats.html.ep:32 themes/default/templates/stats.html.ep:35
msgid "Import URLs"
msgstr ""
#: themes/default/templates/api.html.ep:79
msgid "It will use Lstu's cookies to know which shortened URL it will return statistics for."
msgstr ""
......@@ -121,7 +133,7 @@ msgstr ""
msgid "JSON: success"
msgstr ""
#: themes/default/templates/layouts/default.html.ep:31
#: themes/default/templates/layouts/default.html.ep:37
msgid "License:"
msgstr ""
......@@ -129,7 +141,7 @@ msgstr ""
msgid "Login"
msgstr ""
#: themes/default/templates/layouts/default.html.ep:37
#: themes/default/templates/layouts/default.html.ep:43
msgid "Logout"
msgstr ""
......@@ -137,7 +149,7 @@ msgstr ""
msgid "Logout from admin stats"
msgstr ""
#: themes/default/templates/stats.html.ep:69
#: themes/default/templates/stats.html.ep:84
msgid "Next"
msgstr ""
......@@ -158,11 +170,11 @@ msgstr ""
msgid "Please, check your credentials: unable to authenticate."
msgstr ""
#: themes/default/templates/stats.html.ep:67
#: themes/default/templates/stats.html.ep:82
msgid "Previous"
msgstr ""
#: themes/default/templates/stats.html.ep:35
#: themes/default/templates/stats.html.ep:50
msgid "QRCode"
msgstr ""
......@@ -178,7 +190,7 @@ msgstr ""
msgid "Response:"
msgstr ""
#: themes/default/templates/stats.html.ep:30
#: themes/default/templates/stats.html.ep:45
msgid "Shortened URL"
msgstr ""
......@@ -186,11 +198,15 @@ msgstr ""
msgid "Should always be successful"
msgstr ""
#: themes/default/templates/layouts/default.html.ep:39 themes/default/templates/login.html.ep:16 themes/default/templates/logout.html.ep:5
#: themes/default/templates/layouts/default.html.ep:45 themes/default/templates/login.html.ep:16 themes/default/templates/logout.html.ep:5
msgid "Signin"
msgstr ""
#: themes/default/templates/layouts/default.html.ep:36 themes/default/templates/layouts/default.html.ep:42 themes/default/templates/stats.html.ep:4
#: lib/Lstu/Controller/Lstu.pm:188
msgid "Sorry, unable to parse the provided file"
msgstr ""
#: themes/default/templates/layouts/default.html.ep:42 themes/default/templates/layouts/default.html.ep:48 themes/default/templates/stats.html.ep:4
msgid "Statistics"
msgstr ""
......@@ -210,7 +226,7 @@ msgid "The URL you want to shorten comes from a domain (%1) that is blacklisted
msgstr ""
#. ($c->url_for('/')
#: lib/Lstu/Controller/Admin.pm:134 lib/Lstu/Controller/Lstu.pm:281 lib/Lstu/Controller/Lstu.pm:329
#: lib/Lstu/Controller/Admin.pm:134 lib/Lstu/Controller/Lstu.pm:327 lib/Lstu/Controller/Lstu.pm:375
msgid "The shortened URL %1 doesn't exist."
msgstr ""
......@@ -236,7 +252,7 @@ msgstr ""
msgid "Too many bad passwords. You're banned."
msgstr ""
#: themes/default/templates/api.html.ep:104 themes/default/templates/api.html.ep:95 themes/default/templates/stats.html.ep:29
#: themes/default/templates/api.html.ep:104 themes/default/templates/api.html.ep:95 themes/default/templates/stats.html.ep:44
msgid "URL"
msgstr ""
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ body {
font-family: 'Henny_Penny';
font-style: normal;
font-weight: 400;
src: local('Henny Penny'), local('HennyPenny-Regular'), url(<%= url_for('/font/hennypenny.woff2') %>) format('woff2');
src: local('Henny Penny'), local('HennyPenny-Regular'), url('../font/hennypenny.woff2') format('woff2');
}
.hennypenny {
font-family: 'Henny_Penny', cursive;
......
......@@ -18,7 +18,13 @@
<link rel="apple-touch-icon" sizes="120x120" href="<%= url_for('/img/lstu120.png') %>">
<link rel="apple-touch-icon" sizes="152x152" href="<%= url_for('/img/lstu152.png') %>">
<link rel="apple-touch-icon-precomposed" sizes="128x128" href="<%= url_for('/img/lstu128.png') %>">
% if ($self->app->mode eq 'production') {
%= stylesheet '/css/bootstrap-lstu.min.css'
% } else {
%= stylesheet '/css/bootstrap.min.css'
%= stylesheet '/css/lstu.css'
%= stylesheet '/css/fontelico.css'
% }
</head>
<body>
<div class="container">
......
......@@ -23,6 +23,21 @@
% }
<br>
% }
% if (defined(flash('success_msg'))) {
<h3 class="alert alert-success"><%= flash('success_msg') %></h3>
% }
<form class="form" method="POST" action="<%== url_for 'import_cookie' %>" enctype="multipart/form-data">
<div class="form-group">
<label for="file"><%= l('Import URLs') %></label>
<input type="file" name="file" id="file" required>
</div>
<%= submit_button l('Import URLs'), class => 'btn btn-default btn-primary' %>
<a href="<%= url_for 'export_cookie' %>" class="btn btn-default"><%= l('Export your URLs') %></a>
</form>
<br>
<table class="table table-striped">
<tr>
<th>#</th>
......
......@@ -45,7 +45,13 @@
</p>
<%= content %>
</div>
% if ($self->app->mode eq 'production') {
%= stylesheet '/css/milli-lstu.min.css'
% } else {
%= stylesheet '/css/milligram.min.css'
%= stylesheet '/css/lstu.css'
%= stylesheet '/css/fontelico.css'
% }
% if (defined(flash('short')) && defined(flash('url'))) {
%= javascript url_for('lstu.js')
% }
......
......@@ -21,8 +21,20 @@
% if (defined(flash('msg'))) {
<h3 class="alert alert-danger"><%= flash('msg') %></h3>
% }
<br>
% }
% if (defined(flash('success_msg'))) {
<h3 class="alert alert-success"><%= flash('success_msg') %></h3>
% }
<form class="form" method="POST" action="<%== url_for 'import_cookie' %>" enctype="multipart/form-data">
<fieldset>
<label for="file"><%= l('Import URLs') %></label>
<input type="file" name="file" id="file" required>
</fieldset>
<%= submit_button l('Import URLs'), class => 'button' %>
<a href="<%= url_for 'export_cookie' %>" class="button button-outline"><%= l('Export your URLs') %></a>
</form>
<table class="table table-striped">
<tr>
<th>#</th>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment