mirror of
https://github.com/koniu/recoll-webui.git
synced 2025-10-03 01:39:22 +02:00
import
This commit is contained in:
commit
70ad857091
16 changed files with 1285 additions and 0 deletions
6
examples/firefox-user.js
Normal file
6
examples/firefox-user.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// To allow access to files via recoll-webui include the following in your:
|
||||
// ~/.mozilla/firefox/<profile>/user.js
|
||||
|
||||
user_pref("capability.policy.policynames", "localfilelinks");
|
||||
user_pref("capability.policy.localfilelinks.sites", "http://localhost:8080");
|
||||
user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
|
10
static/extra.js
Normal file
10
static/extra.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
$(document).ready(function(){
|
||||
$("form").submit(function() {
|
||||
$("input").blur()
|
||||
$("#fade").height($("#searchbox").height()+1)
|
||||
$("#fade").fadeIn("slow")
|
||||
})
|
||||
if ($("#results").length) { $("input").blur() }
|
||||
$('input[name="after"]').jdPicker({});
|
||||
$('input[name="before"]').jdPicker();
|
||||
})
|
180
static/jdpicker.css
Normal file
180
static/jdpicker.css
Normal file
|
@ -0,0 +1,180 @@
|
|||
.jdpicker_w {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector * {
|
||||
width: auto;
|
||||
height: auto;
|
||||
border: none;
|
||||
background: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
text-decoration: none;
|
||||
font-size:12px;
|
||||
}
|
||||
.jdpicker_w .date_selector {
|
||||
background: #FFF;
|
||||
border: 1px solid black;
|
||||
padding: 5px;
|
||||
margin: -1px 0 0 0;
|
||||
position: absolute;
|
||||
z-index: 100000;
|
||||
display: none;
|
||||
width:210px
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector table{
|
||||
width:210px;
|
||||
margin-left:3px;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_clearer{
|
||||
color: #a00;
|
||||
padding-left:3px;
|
||||
cursor:pointer;
|
||||
font-weight:bold;
|
||||
font-family:sans-serif
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector_ieframe {
|
||||
position: absolute;
|
||||
z-index: 99999;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.jdpicker_w .error_msg{
|
||||
display:none;
|
||||
text-align:center;
|
||||
font-size:0.8em;
|
||||
color:#666
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector .nav {
|
||||
width: 17.5em; /* 7 * 2.5em */
|
||||
}
|
||||
.jdpicker_w .date_selector .month_nav, .jdpicker_w .date_selector .year_nav {
|
||||
margin: 0 0 3px 0;
|
||||
padding: 0;
|
||||
display: block;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
}
|
||||
.jdpicker_w .date_selector .month_nav {
|
||||
float: left;
|
||||
width: 56%;
|
||||
}
|
||||
.jdpicker_w .date_selector .year_nav {
|
||||
float: right;
|
||||
width: 37%;
|
||||
position:relative;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector .month_nav select {
|
||||
width:75px;
|
||||
margin: 0 auto;
|
||||
border:1px solid #ccc;
|
||||
position:relative;
|
||||
top:1px
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector .year_nav .year_input {
|
||||
text-align:center;
|
||||
width:36px;
|
||||
border:1px solid #ccc;
|
||||
position:relative;
|
||||
top:2px
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector .month_name, .jdpicker_w .date_selector .year_name {
|
||||
font-weight: bold;
|
||||
line-height: 20px;
|
||||
}
|
||||
.jdpicker_w .date_selector .button {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
line-height: 17px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
font-size: 120%;
|
||||
overflow: hidden;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector .button:hover, .jdpicker_w .date_selector .button.hover {
|
||||
background: none;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
background: #ccc;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector .prev {
|
||||
left: 0;
|
||||
}
|
||||
.jdpicker_w .date_selector .next {
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector table {
|
||||
margin:0 auto;
|
||||
|
||||
clear: both;
|
||||
}
|
||||
.jdpicker_w .date_selector th{
|
||||
padding-top:5px;
|
||||
padding-bottom:5px;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector th, .jdpicker_w .date_selector td {
|
||||
text-align: center;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector th.week_label{
|
||||
font-weight:normal;
|
||||
font-style:italic;
|
||||
font-size:80%;
|
||||
width:25px
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector .week_num, .jdpicker_w .date_selector .hover .week_num, .jdpicker_w .date_selector .selected .week_num{
|
||||
font-style:italic;
|
||||
color:#333 !important;
|
||||
vertical-align:bottom !important;
|
||||
text-align:right;
|
||||
border:none !important;
|
||||
font-size:70%;
|
||||
background:#FCFCFC !important;
|
||||
padding-right:4px;
|
||||
}
|
||||
|
||||
.jdpicker_w .date_selector td {
|
||||
line-height: 2em;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
color: #003C78;
|
||||
background: white;
|
||||
}
|
||||
.jdpicker_w .date_selector td.today {
|
||||
color: darkorange !important;
|
||||
}
|
||||
.jdpicker_w .date_selector td.unselected_month {
|
||||
color: #ccc;
|
||||
}
|
||||
.jdpicker_w .date_selector td.selectable_day, .jdpicker_w .date_selector tr.selectable_week td {
|
||||
cursor: pointer;
|
||||
color:#333
|
||||
}
|
||||
.jdpicker_w .date_selector td.selected, .jdpicker_w .date_selector tr.selected td{
|
||||
background: lightgreen;
|
||||
font-weight: bold;
|
||||
}
|
||||
.jdpicker_w .date_selector tr.selectable_week.hover td, .jdpicker_w .date_selector td.selectable_day.hover {
|
||||
color: white;
|
||||
background: #ccc;
|
||||
}
|
562
static/jdpicker.js
Normal file
562
static/jdpicker.js
Normal file
|
@ -0,0 +1,562 @@
|
|||
/*
|
||||
jdPicker 1.0
|
||||
Requires jQuery version: >= 1.2.6
|
||||
|
||||
2010 - ? -- Paul Da Silva, AMJ Groupe
|
||||
2012 - :P -- koniu@riseup.net (minor changes to controls/style)
|
||||
|
||||
Copyright (c) 2007-2008 Jonathan Leighton & Torchbox Ltd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
jdPicker = (function($) {
|
||||
|
||||
function jdPicker(el, opts) {
|
||||
if (typeof(opts) != "object") opts = {};
|
||||
$.extend(this, jdPicker.DEFAULT_OPTS, opts);
|
||||
|
||||
this.input = $(el);
|
||||
this.bindMethodsToObj("show", "hide", "hideIfClickOutside", "keydownHandler", "selectDate");
|
||||
|
||||
this.build();
|
||||
this.selectDate();
|
||||
|
||||
this.hide();
|
||||
};
|
||||
jdPicker.DEFAULT_OPTS = {
|
||||
month_names: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
||||
short_month_names: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
||||
short_day_names: ["S", "M", "T", "W", "T", "F", "S"],
|
||||
error_out_of_range: "Selected date is out of range",
|
||||
selectable_days: [0, 1, 2, 3, 4, 5, 6],
|
||||
non_selectable: [],
|
||||
rec_non_selectable: [],
|
||||
start_of_week: 1,
|
||||
show_week: 0,
|
||||
select_week: 0,
|
||||
week_label: "",
|
||||
date_min: "",
|
||||
date_max: "",
|
||||
date_format: "YYYY/mm/dd"
|
||||
};
|
||||
jdPicker.prototype = {
|
||||
build: function() {
|
||||
|
||||
this.wrapp = this.input.wrap('<div class="jdpicker_w">');
|
||||
|
||||
switch (this.date_format){
|
||||
case "dd/mm/YYYY":
|
||||
this.reg = new RegExp(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
|
||||
this.date_decode = "new Date(matches[3], parseInt(matches[2]-1), matches[1]);";
|
||||
this.date_encode = 'this.strpad(date.getDate()) + "/" + this.strpad(date.getMonth()+1) + "/" + date.getFullYear();';
|
||||
this.date_encode_s = 'this.strpad(date.getDate()) + "/" + this.strpad(date.getMonth()+1)';
|
||||
break;
|
||||
case "FF dd YYYY":
|
||||
this.reg = new RegExp(/^([a-zA-Z]+) (\d{1,2}) (\d{4})$/);
|
||||
this.date_decode = "new Date(matches[3], this.indexFor(this.month_names, matches[1]), matches[2]);";
|
||||
this.date_encode = 'this.month_names[date.getMonth()] + " " + this.strpad(date.getDate()) + " " + date.getFullYear();';
|
||||
this.date_encode_s = 'this.month_names[date.getMonth()] + " " + this.strpad(date.getDate());';
|
||||
break;
|
||||
case "dd MM YYYY":
|
||||
this.reg = new RegExp(/^(\d{1,2}) ([a-zA-Z]{3}) (\d{4})$/);
|
||||
this.date_decode = "new Date(matches[3], this.indexFor(this.short_month_names, matches[2]), matches[1]);";
|
||||
this.date_encode = 'this.strpad(date.getDate()) + " " + this.short_month_names[date.getMonth()] + " " + date.getFullYear();';
|
||||
this.date_encode_s = 'this.strpad(date.getDate()) + " " + this.short_month_names[date.getMonth()];';
|
||||
break;
|
||||
case "MM dd YYYY":
|
||||
this.reg = new RegExp(/^([a-zA-Z]{3}) (\d{1,2}) (\d{4})$/);
|
||||
this.date_decode = "new Date(matches[3], this.indexFor(this.short_month_names, matches[1]), matches[2]);";
|
||||
this.date_encode = 'this.short_month_names[date.getMonth()] + " " + this.strpad(date.getDate()) + " " + date.getFullYear();';
|
||||
this.date_encode_s = 'this.short_month_names[date.getMonth()] + " " + this.strpad(date.getDate());';
|
||||
break;
|
||||
case "dd FF YYYY":
|
||||
this.reg = new RegExp(/^(\d{1,2}) ([a-zA-Z]+) (\d{4})$/);
|
||||
this.date_decode = "new Date(matches[3], this.indexFor(this.month_names, matches[2]), matches[1]);";
|
||||
this.date_encode = 'this.strpad(date.getDate()) + " " + this.month_names[date.getMonth()] + " " + date.getFullYear();';
|
||||
this.date_encode_s = 'this.strpad(date.getDate()) + " " + this.month_names[date.getMonth()];';
|
||||
break;
|
||||
case "YYYY-mm-dd":
|
||||
default:
|
||||
this.reg = new RegExp(/^(\d{4})\-(\d{1,2})\-(\d{1,2})$/);
|
||||
this.date_decode = "new Date(matches[1], parseInt(matches[2]-1), matches[3]);";
|
||||
this.date_encode = 'date.getFullYear() + "-" + this.strpad(date.getMonth()+1) + "-" + this.strpad(date.getDate());';
|
||||
this.date_encode_s = 'this.strpad(date.getMonth()+1) + "-" + this.strpad(date.getDate());';
|
||||
break;
|
||||
}
|
||||
|
||||
if(this.date_max != "" && this.date_max.match(this.reg)){
|
||||
var matches = this.date_max.match(this.reg);
|
||||
this.date_max = eval(this.date_decode);
|
||||
}else
|
||||
this.date_max = "";
|
||||
|
||||
if(this.date_min != "" && this.date_min.match(this.reg)){
|
||||
var matches = this.date_min.match(this.reg);
|
||||
this.date_min = eval(this.date_decode);
|
||||
}else
|
||||
this.date_min = "";
|
||||
|
||||
var monthNav = $('<p class="month_nav">' +
|
||||
'<span class="button prev" title="[PageUp]">«</span>' +
|
||||
' <span class="month_name"></span> ' +
|
||||
'<span class="button next" title="[PageDown]">»</span>' +
|
||||
'</p>');
|
||||
|
||||
this.monthNameSpan = $(".month_name", monthNav);
|
||||
$(".prev", monthNav).click(this.bindToObj(function() { this.moveMonthBy(-1); }));
|
||||
$(".next", monthNav).click(this.bindToObj(function() { this.moveMonthBy(1); }));
|
||||
|
||||
this.monthNameSpan.dblclick(this.bindToObj(function(){
|
||||
this.monthNameSpan.empty().append(this.getMonthSelect());
|
||||
$('select', this.monthNameSpan).change(this.bindToObj(function(){
|
||||
this.moveMonthBy(parseInt($('select :selected', this.monthNameSpan).val()) - this.currentMonth.getMonth());
|
||||
}));
|
||||
}));
|
||||
|
||||
var yearNav = $('<p class="year_nav">' +
|
||||
'<span class="button prev" title="[Shift+PageUp]">«</span>' +
|
||||
' <span class="year_name" id="year_name"></span> ' +
|
||||
'<span class="button next" title="[Shift+PageDown]">»</span>' +
|
||||
'</p>');
|
||||
|
||||
this.yearNameSpan = $(".year_name", yearNav);
|
||||
$(".prev", yearNav).click(this.bindToObj(function() { this.moveMonthBy(-12); }));
|
||||
$(".next", yearNav).click(this.bindToObj(function() { this.moveMonthBy(12); }));
|
||||
|
||||
this.yearNameSpan.dblclick(this.bindToObj(function(){
|
||||
|
||||
if($('.year_name input', this.rootLayers).length==0){
|
||||
var initialDate = this.yearNameSpan.html();
|
||||
|
||||
var yearNameInput = $('<input type="text" class="text year_input" value="'+initialDate+'" />');
|
||||
this.yearNameSpan.empty().append(yearNameInput);
|
||||
|
||||
$(".year_input", yearNav).keyup(this.bindToObj(function(){
|
||||
if($('input',this.yearNameSpan).val().length == 4 && $('input',this.yearNameSpan).val() != initialDate && parseInt($('input',this.yearNameSpan).val()) == $('input',this.yearNameSpan).val()){
|
||||
this.moveMonthBy(parseInt(parseInt(parseInt($('input',this.yearNameSpan).val()) - initialDate)*12));
|
||||
}else if($('input',this.yearNameSpan).val().length>4)
|
||||
$('input',this.yearNameSpan).val($('input',this.yearNameSpan).val().substr(0, 4));
|
||||
}));
|
||||
|
||||
$('input',this.yearNameSpan).focus();
|
||||
$('input',this.yearNameSpan).select();
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
var error_msg = $('<div class="error_msg"></div>');
|
||||
|
||||
var nav = $('<div class="nav"></div>').append(error_msg, monthNav, yearNav);
|
||||
|
||||
var tableShell = "<table><thead><tr>";
|
||||
|
||||
if(this.show_week == 1) tableShell +='<th class="week_label">'+(this.week_label)+'</th>';
|
||||
|
||||
$(this.adjustDays(this.short_day_names)).each(function() {
|
||||
tableShell += "<th>" + this + "</th>";
|
||||
});
|
||||
|
||||
tableShell += "</tr></thead><tbody></tbody></table>";
|
||||
|
||||
var style = (this.input.context.type=="hidden")?' style="display:block; position:static; margin:0 auto"':'';
|
||||
|
||||
this.dateSelector = this.rootLayers = $('<div class="date_selector" '+style+'></div>').append(nav, tableShell).insertAfter(this.input);
|
||||
|
||||
if ($.browser.msie && $.browser.version < 7) {
|
||||
|
||||
this.ieframe = $('<iframe class="date_selector_ieframe" frameborder="0" src="#"></iframe>').insertBefore(this.dateSelector);
|
||||
this.rootLayers = this.rootLayers.add(this.ieframe);
|
||||
|
||||
$(".button", nav).mouseover(function() { $(this).addClass("hover"); });
|
||||
$(".button", nav).mouseout(function() { $(this).removeClass("hover"); });
|
||||
};
|
||||
|
||||
this.tbody = $("tbody", this.dateSelector);
|
||||
|
||||
this.input.change(this.bindToObj(function() { this.selectDate(); }));
|
||||
|
||||
this.selectDate();
|
||||
|
||||
},
|
||||
|
||||
selectMonth: function(date) {
|
||||
var newMonth = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||
if(this.isNewDateAllowed(newMonth)){
|
||||
if (!this.currentMonth || !(this.currentMonth.getFullYear() == newMonth.getFullYear() &&
|
||||
this.currentMonth.getMonth() == newMonth.getMonth())) {
|
||||
|
||||
this.currentMonth = newMonth;
|
||||
|
||||
var rangeStart = this.rangeStart(date), rangeEnd = this.rangeEnd(date);
|
||||
var numDays = this.daysBetween(rangeStart, rangeEnd);
|
||||
var dayCells = "";
|
||||
|
||||
for (var i = 0; i <= numDays; i++) {
|
||||
var currentDay = new Date(rangeStart.getFullYear(), rangeStart.getMonth(), rangeStart.getDate() + i, 12, 00);
|
||||
|
||||
if (this.isFirstDayOfWeek(currentDay)){
|
||||
|
||||
var firstDayOfWeek = currentDay;
|
||||
var lastDayOfWeek = new Date(currentDay.getFullYear(), currentDay.getMonth(), currentDay.getDate()+6, 12, 00);
|
||||
|
||||
if(this.select_week && this.isNewDateAllowed(firstDayOfWeek))
|
||||
dayCells += "<tr date='" + this.dateToString(currentDay) + "' class='selectable_week'>";
|
||||
else
|
||||
dayCells += "<tr>";
|
||||
|
||||
if(this.show_week==1)
|
||||
dayCells += '<td class="week_num">'+this.getWeekNum(currentDay)+'</td>';
|
||||
}
|
||||
if ((this.select_week == 0 && currentDay.getMonth() == date.getMonth() && this.isNewDateAllowed(currentDay) && !this.isHoliday(currentDay)) || (this.select_week==1 && currentDay.getMonth() == date.getMonth() && this.isNewDateAllowed(firstDayOfWeek))) {
|
||||
dayCells += '<td class="selectable_day" date="' + this.dateToString(currentDay) + '">' + currentDay.getDate() + '</td>';
|
||||
} else {
|
||||
dayCells += '<td class="unselected_month" date="' + this.dateToString(currentDay) + '">' + currentDay.getDate() + '</td>';
|
||||
};
|
||||
|
||||
if (this.isLastDayOfWeek(currentDay)) dayCells += "</tr>";
|
||||
};
|
||||
this.tbody.empty().append(dayCells);
|
||||
|
||||
this.monthNameSpan.empty().append(this.monthName(date));
|
||||
this.yearNameSpan.empty().append(this.currentMonth.getFullYear());
|
||||
|
||||
if(this.select_week == 0){
|
||||
$(".selectable_day", this.tbody).click(this.bindToObj(function(event) {
|
||||
this.changeInput($(event.target).attr("date"));if(this.input.context.type!="hidden") this.hide();
|
||||
}));
|
||||
}else{
|
||||
$(".selectable_week", this.tbody).click(this.bindToObj(function(event) {
|
||||
this.changeInput($(event.target.parentNode).attr("date"));if(this.input.context.type!="hidden") this.hide();
|
||||
}));
|
||||
}
|
||||
|
||||
$("td[date='" + this.dateToString(new Date()) + "']", this.tbody).addClass("today");
|
||||
if(this.select_week == 1){
|
||||
$("tr", this.tbody).mouseover(function() { $(this).addClass("hover"); });
|
||||
$("tr", this.tbody).mouseout(function() { $(this).removeClass("hover"); });
|
||||
}else{
|
||||
$("td.selectable_day", this.tbody).mouseover(function() { $(this).addClass("hover"); });
|
||||
$("td.selectable_day", this.tbody).mouseout(function() { $(this).removeClass("hover"); });
|
||||
}
|
||||
};
|
||||
|
||||
$('.selected', this.tbody).removeClass("selected");
|
||||
$('td[date="' + this.selectedDateString + '"], tr[date="' + this.selectedDateString + '"]', this.tbody).addClass("selected");
|
||||
}else
|
||||
this.show_error(this.error_out_of_range);
|
||||
},
|
||||
|
||||
selectDate: function(date) {
|
||||
if (typeof(date) == "undefined") {
|
||||
date = this.stringToDate(this.input.val());
|
||||
};
|
||||
if (!date) date = new Date();
|
||||
|
||||
if(this.select_week == 1 && !this.isFirstDayOfWeek(date))
|
||||
date = new Date(date.getFullYear(), date.getMonth(), (date.getDate() - date.getDay() + this.start_of_week), 12, 00);
|
||||
|
||||
if(this.isNewDateAllowed(date)){
|
||||
this.selectedDate = date;
|
||||
this.selectedDateString = this.dateToString(this.selectedDate);
|
||||
this.selectMonth(this.selectedDate);
|
||||
}else if((this.date_min) && this.daysBetween(this.date_min, date)<0){
|
||||
this.selectedDate = this.date_min;
|
||||
this.selectMonth(this.date_min);
|
||||
this.input.val(" ");
|
||||
}else{
|
||||
this.selectMonth(this.date_max);
|
||||
this.input.val(" ");
|
||||
}
|
||||
},
|
||||
|
||||
isNewDateAllowed: function(date){
|
||||
return ((!this.date_min) || this.daysBetween(this.date_min, date)>=0) && ((!this.date_max) || this.daysBetween(date, this.date_max)>=0);
|
||||
},
|
||||
|
||||
isHoliday: function(date){
|
||||
return ((this.indexFor(this.selectable_days, date.getDay())===false || this.indexFor(this.non_selectable, this.dateToString(date))!==false) || this.indexFor(this.rec_non_selectable, this.dateToShortString(date))!==false);
|
||||
},
|
||||
|
||||
changeInput: function(dateString) {
|
||||
this.input.val(dateString).change();
|
||||
},
|
||||
|
||||
show: function() {
|
||||
$('.error_msg', this.rootLayers).css('display', 'none');
|
||||
this.rootLayers.slideDown("fast");
|
||||
$([window, document.body]).click(this.hideIfClickOutside);
|
||||
this.input.unbind("focus", this.show);
|
||||
$(document.body).keydown(this.keydownHandler);
|
||||
this.setPosition();
|
||||
this.orig_date = this.input.val()
|
||||
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
if(this.input.context.type!="hidden"){
|
||||
this.rootLayers.slideUp("fast");
|
||||
$([window, document.body]).unbind("click", this.hideIfClickOutside);
|
||||
this.input.focus(this.show);
|
||||
$(document.body).unbind("keydown", this.keydownHandler);
|
||||
}
|
||||
},
|
||||
|
||||
hideIfClickOutside: function(event) {
|
||||
if (event.target != this.input[0] && !this.insideSelector(event)) {
|
||||
this.hide();
|
||||
};
|
||||
},
|
||||
|
||||
insideSelector: function(event) {
|
||||
var offset = this.dateSelector.position();
|
||||
offset.right = offset.left + this.dateSelector.outerWidth();
|
||||
offset.bottom = offset.top + this.dateSelector.outerHeight();
|
||||
|
||||
return event.pageY < offset.bottom &&
|
||||
event.pageY > offset.top &&
|
||||
event.pageX < offset.right &&
|
||||
event.pageX > offset.left;
|
||||
},
|
||||
|
||||
keydownHandler: function(event) {
|
||||
switch (event.keyCode)
|
||||
{
|
||||
case 9:
|
||||
this.hide()
|
||||
return;
|
||||
break;
|
||||
case 27:
|
||||
this.input.val(this.orig_date)
|
||||
this.hide();
|
||||
return;
|
||||
break;
|
||||
case 32:
|
||||
if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
|
||||
this.changeInput(this.selectedDateString); if(this.input.context.type!="hidden") this.hide();
|
||||
break;
|
||||
case 33:
|
||||
this.moveDateMonthBy(event.shiftKey ? -12 : -1);
|
||||
if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
|
||||
this.changeInput(this.selectedDateString);
|
||||
break;
|
||||
case 34:
|
||||
this.moveDateMonthBy(event.shiftKey ? 12 : 1);
|
||||
if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
|
||||
this.changeInput(this.selectedDateString);
|
||||
break;
|
||||
case 38:
|
||||
this.moveDateBy(-7);
|
||||
if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
|
||||
this.changeInput(this.selectedDateString);
|
||||
break;
|
||||
case 40:
|
||||
this.moveDateBy(7);
|
||||
if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
|
||||
this.changeInput(this.selectedDateString);
|
||||
break;
|
||||
case 37:
|
||||
if(this.select_week == 0) this.moveDateBy(-1);
|
||||
if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
|
||||
this.changeInput(this.selectedDateString);
|
||||
break;
|
||||
case 39:
|
||||
if(this.select_week == 0) this.moveDateBy(1);
|
||||
if(this.isNewDateAllowed(this.stringToDate(this.selectedDateString)) && !this.isHoliday(this.stringToDate(this.selectedDateString)))
|
||||
this.changeInput(this.selectedDateString);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
},
|
||||
|
||||
stringToDate: function(string) {
|
||||
var matches;
|
||||
|
||||
if (matches = string.match(this.reg)) {
|
||||
if(matches[3]==0 && matches[2]==0 && matches[1]==0)
|
||||
return null;
|
||||
else
|
||||
return eval(this.date_decode);
|
||||
} else {
|
||||
return null;
|
||||
};
|
||||
},
|
||||
|
||||
dateToString: function(date) {
|
||||
return eval(this.date_encode);
|
||||
},
|
||||
|
||||
dateToShortString: function(date){
|
||||
return eval(this.date_encode_s);
|
||||
},
|
||||
|
||||
setPosition: function() {
|
||||
var offset = this.input.offset();
|
||||
this.rootLayers.css({
|
||||
top: offset.top + this.input.outerHeight(),
|
||||
left: offset.left
|
||||
});
|
||||
|
||||
if (this.ieframe) {
|
||||
this.ieframe.css({
|
||||
width: this.dateSelector.outerWidth(),
|
||||
height: this.dateSelector.outerHeight()
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
moveDateBy: function(amount) {
|
||||
var newDate = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth(), this.selectedDate.getDate() + amount);
|
||||
this.selectDate(newDate);
|
||||
},
|
||||
|
||||
moveDateMonthBy: function(amount) {
|
||||
var newDate = new Date(this.selectedDate.getFullYear(), this.selectedDate.getMonth() + amount, this.selectedDate.getDate());
|
||||
if (newDate.getMonth() == this.selectedDate.getMonth() + amount + 1) {
|
||||
newDate.setDate(0);
|
||||
};
|
||||
this.selectDate(newDate);
|
||||
},
|
||||
|
||||
moveMonthBy: function(amount) {
|
||||
if(amount<0)
|
||||
var newMonth = new Date(this.currentMonth.getFullYear(), this.currentMonth.getMonth() + amount+1, -1);
|
||||
else
|
||||
var newMonth = new Date(this.currentMonth.getFullYear(), this.currentMonth.getMonth() + amount, 1);
|
||||
this.selectMonth(newMonth);
|
||||
},
|
||||
|
||||
monthName: function(date) {
|
||||
return this.month_names[date.getMonth()];
|
||||
},
|
||||
|
||||
getMonthSelect:function(){
|
||||
var month_select = '<select>';
|
||||
for(var i = 0; i<this.month_names.length; i++){
|
||||
if(i==this.currentMonth.getMonth())
|
||||
month_select += '<option value="'+(i)+'" selected="selected">'+this.month_names[i]+'</option>';
|
||||
else
|
||||
month_select += '<option value="'+(i)+'">'+this.month_names[i]+'</option>';
|
||||
}
|
||||
month_select += '</select>';
|
||||
|
||||
return month_select;
|
||||
},
|
||||
|
||||
bindToObj: function(fn) {
|
||||
var self = this;
|
||||
return function() { return fn.apply(self, arguments) };
|
||||
},
|
||||
|
||||
bindMethodsToObj: function() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
this[arguments[i]] = this.bindToObj(this[arguments[i]]);
|
||||
};
|
||||
},
|
||||
|
||||
indexFor: function(array, value) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (value == array[i]) return i;
|
||||
};
|
||||
return false;
|
||||
},
|
||||
|
||||
monthNum: function(month_name) {
|
||||
return this.indexFor(this.month_names, month_name);
|
||||
},
|
||||
|
||||
shortMonthNum: function(month_name) {
|
||||
return this.indexFor(this.short_month_names, month_name);
|
||||
},
|
||||
|
||||
shortDayNum: function(day_name) {
|
||||
return this.indexFor(this.short_day_names, day_name);
|
||||
},
|
||||
|
||||
daysBetween: function(start, end) {
|
||||
start = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate());
|
||||
end = Date.UTC(end.getFullYear(), end.getMonth(), end.getDate());
|
||||
return (end - start) / 86400000;
|
||||
},
|
||||
|
||||
changeDayTo: function(dayOfWeek, date, direction) {
|
||||
var difference = direction * (Math.abs(date.getDay() - dayOfWeek - (direction * 7)) % 7);
|
||||
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + difference);
|
||||
},
|
||||
|
||||
rangeStart: function(date) {
|
||||
return this.changeDayTo(this.start_of_week, new Date(date.getFullYear(), date.getMonth()), -1);
|
||||
},
|
||||
|
||||
rangeEnd: function(date) {
|
||||
return this.changeDayTo((this.start_of_week - 1) % 7, new Date(date.getFullYear(), date.getMonth() + 1, 0), 1);
|
||||
},
|
||||
|
||||
isFirstDayOfWeek: function(date) {
|
||||
return date.getDay() == this.start_of_week;
|
||||
},
|
||||
|
||||
getWeekNum:function(date){
|
||||
date_week= new Date(date.getFullYear(), date.getMonth(), date.getDate()+6);
|
||||
var firstDayOfYear = new Date(date_week.getFullYear(), 0, 1, 12, 00);
|
||||
var n = parseInt(this.daysBetween(firstDayOfYear, date_week)) + 1;
|
||||
return Math.floor((date_week.getDay() + n + 5)/7) - Math.floor(date_week.getDay() / 5);
|
||||
},
|
||||
|
||||
isLastDayOfWeek: function(date) {
|
||||
return date.getDay() == (this.start_of_week - 1) % 7;
|
||||
},
|
||||
|
||||
show_error: function(error){
|
||||
$('.error_msg', this.rootLayers).html(error);
|
||||
$('.error_msg', this.rootLayers).slideDown(400, function(){
|
||||
setTimeout("$('.error_msg', this.rootLayers).slideUp(200);", 2000);
|
||||
});
|
||||
},
|
||||
|
||||
adjustDays: function(days) {
|
||||
var newDays = [];
|
||||
for (var i = 0; i < days.length; i++) {
|
||||
newDays[i] = days[(i + this.start_of_week) % 7];
|
||||
};
|
||||
return newDays;
|
||||
},
|
||||
|
||||
strpad: function(num){
|
||||
if(parseInt(num)<10) return "0"+parseInt(num);
|
||||
else return parseInt(num);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$.fn.jdPicker = function(opts) {
|
||||
return this.each(function() { new jdPicker(this, opts); });
|
||||
};
|
||||
$.jdPicker = { initialize: function(opts) {
|
||||
$("input.jdpicker").jdPicker(opts);
|
||||
} };
|
||||
|
||||
return jdPicker;
|
||||
})(jQuery);
|
||||
|
||||
$($.jdPicker.initialize);
|
2
static/jquery.js
vendored
Normal file
2
static/jquery.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
static/recoll.png
Normal file
BIN
static/recoll.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 457 B |
117
static/style.css
Normal file
117
static/style.css
Normal file
|
@ -0,0 +1,117 @@
|
|||
body {
|
||||
margin: 0;
|
||||
font-family: sans;
|
||||
}
|
||||
#searchbox {
|
||||
background: #eee;
|
||||
border-bottom: 1px solid #666;
|
||||
}
|
||||
|
||||
#status { padding: 1.5em; }
|
||||
#found { float: left; }
|
||||
#downloads { position: fixed; bottom: 2px; right: 7px; margin-left: 1em; }
|
||||
#downloads a {
|
||||
border: 1px solid #aaa;
|
||||
padding: 5px;
|
||||
background: #f8f8f8;
|
||||
color: #999;
|
||||
font-size: 7pt;
|
||||
}
|
||||
#downloads a:hover { background: #ccc; color: white }
|
||||
|
||||
#results { padding: 1em; }
|
||||
.search-result {
|
||||
margin-left: 15%;
|
||||
margin-right: 15%;
|
||||
background: #fff;
|
||||
padding-bottom: 0.5em;
|
||||
padding-top: 1em;
|
||||
}
|
||||
.search-result-title, .search-result-ipath {
|
||||
margin-bottom: 6px;
|
||||
font-weight: bold;
|
||||
font-size: 12pt;
|
||||
float: left;
|
||||
}
|
||||
.search-result-ipath { color: #aaa; padding-left: 1em; }
|
||||
.search-result-title a { text-decoration: none; color: black; }
|
||||
.search-result-author {
|
||||
clear: both;
|
||||
color: #666;
|
||||
font-size: 7pt;
|
||||
margin-bottom: 6px
|
||||
}
|
||||
.search-result-number {
|
||||
width: 4em;
|
||||
float: left;
|
||||
margin-left: -5em;
|
||||
text-align: right;
|
||||
}
|
||||
.search-result-number a { font-size: 10pt; font-weight: normal; color:#bbb; background: #f8f8f8; padding: 4px; }
|
||||
.search-result-number a:hover { color:white; background: #ccc; }
|
||||
.search-result-snippet {
|
||||
margin-left: 1px;
|
||||
margin-top: 2px;
|
||||
font-size: 10pt;
|
||||
text-align: justify;
|
||||
border-left: 3px solid #ddd;
|
||||
padding-left: 1em;
|
||||
color: #444; clear: both;
|
||||
font-family: serif;
|
||||
}
|
||||
.search-result-url { clear:left; }
|
||||
.search-result-url a { color: #5a5; font-size: 8pt; float: left; margin-right: 1em;}
|
||||
.search-result-date { color: #777; font-size: 8pt; float: right; margin-bottom: 7px; }
|
||||
.search-result-size { color: #777; font-size: 8pt; float: right; display: none; }
|
||||
.search-result-highlight { color: #7E1212; font-weight: bold; }
|
||||
.gray { color: #aaa }
|
||||
|
||||
a { text-decoration: none }
|
||||
table td {
|
||||
padding: 10;
|
||||
border-right: 1px dotted black ;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table td:last-child {
|
||||
border-right: 0px;
|
||||
}
|
||||
form { margin: 0 }
|
||||
input, select {
|
||||
margin-top: 2px;
|
||||
margin-bottom: 2px;
|
||||
background: white;
|
||||
border: 1px solid #999;
|
||||
padding: 3px;
|
||||
width: 100%;
|
||||
color: #555;
|
||||
}
|
||||
input:focus, button:focus, select:focus{
|
||||
border: 1px solid black;
|
||||
color: black;
|
||||
}
|
||||
input[type=button],input[type=reset],input[type=submit] { width: 32%; }
|
||||
input[type=button]:hover,input[type=reset]:hover,input[type=submit]:hover{ color:white; background: #ccc; cursor: pointer; }
|
||||
input[type=reset]:hover,input[type=submit]:hover { }
|
||||
input[name=before], input[name=after] { width: 45% }
|
||||
tr { vertical-align: top }
|
||||
|
||||
#settings-box {
|
||||
padding: 1em;
|
||||
position: absolute;
|
||||
top: 10%;
|
||||
left: 30%;
|
||||
right: 30%;
|
||||
background: #eee;
|
||||
border: 1px solid #999;
|
||||
}
|
||||
hr { border: 1px solid #999 }
|
||||
|
||||
#fade {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
opacity: 0.7;
|
||||
background: white;
|
||||
display: none;
|
||||
}
|
||||
|
2
views/footer.tpl
Normal file
2
views/footer.tpl
Normal file
|
@ -0,0 +1,2 @@
|
|||
</body>
|
||||
</html>
|
13
views/header.tpl
Normal file
13
views/header.tpl
Normal file
|
@ -0,0 +1,13 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>recoll{{title}}</title>
|
||||
<link rel="stylesheet" type="text/css" href="static/style.css">
|
||||
<script type="text/javascript" src="static/jquery.js"></script>
|
||||
<script type="text/javascript" src="static/extra.js"></script>
|
||||
|
||||
<script type="text/javascript" src="static/jdpicker.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="static/jdpicker.css">
|
||||
<link rel="icon" type="image/png" href="static/recoll.png">
|
||||
</head>
|
||||
<body>
|
||||
<div id="fade"></div>
|
3
views/main.tpl
Normal file
3
views/main.tpl
Normal file
|
@ -0,0 +1,3 @@
|
|||
%include header title=""
|
||||
%include search query=query, dirs=dirs, sorts=sorts
|
||||
%include footer
|
53
views/results.tpl
Normal file
53
views/results.tpl
Normal file
|
@ -0,0 +1,53 @@
|
|||
%import shlex, unicodedata
|
||||
%def strip_accents(s): return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
|
||||
%include header title=" - " + query['keywords']+" ("+str(len(res))+")"
|
||||
%include search query=query, dirs=dirs, sorts=sorts
|
||||
<div id="status">
|
||||
<div id="found">
|
||||
Found <b>{{len(res)}}</b> matching: <b><i>{{qs}}</i></b>
|
||||
<small class="gray">({{time.seconds}}.{{time.microseconds/10000}}s)</small>
|
||||
</div>
|
||||
%if len(res) > 0:
|
||||
<div id="downloads">
|
||||
<a href="../json?{{query_string}}">JSON</a>
|
||||
<a href="../csv?{{query_string}}">CSV</a>
|
||||
</div>
|
||||
%end
|
||||
</div>
|
||||
<div id="results">
|
||||
%for i in range(0, len(res)):
|
||||
%d = res[i]
|
||||
<div class="search-result">
|
||||
<div class="search-result-number"><a href="#r{{d['sha']}}">#{{i+1}}</a>
|
||||
|
||||
</div>
|
||||
<div class="search-result-title" id="r{{d['sha']}}" title="{{d['abstract']}}"><a href="{{d['url']}}">{{d['label']}}</a></div>
|
||||
%if len(d['ipath']) > 0:
|
||||
<div class="search-result-ipath">[{{d['ipath']}}]</div>
|
||||
%end
|
||||
%if len(d['author']) > 0:
|
||||
<div class="search-result-author">{{d['author']}}</div>
|
||||
%end
|
||||
<div class="search-result-url">
|
||||
<a href="{{d['url'].replace('/'+d['filename'],'')}}">
|
||||
%urllabel = d['url'].replace('/'+d['filename'],'').replace('file://','')
|
||||
%for r in roots:
|
||||
%urllabel = urllabel.replace(r.rsplit('/',1)[0] + '/' , '')
|
||||
%end
|
||||
{{urllabel}}
|
||||
</a>
|
||||
</div>
|
||||
<div class="search-result-date">{{d['time']}}</div>
|
||||
%for q in shlex.split(query['keywords'].replace("'","\\'")):
|
||||
%if not q == "OR":
|
||||
% w = strip_accents(q.decode('utf-8').lower()).encode('utf-8')
|
||||
% d['snippet'] = d['snippet'].replace(w,'<span class="search-result-highlight">'+w+'</span>')
|
||||
%end
|
||||
%end
|
||||
<div class="search-result-snippet">{{!d['snippet']}}</div>
|
||||
</div>
|
||||
%end
|
||||
</div>
|
||||
%include footer
|
||||
<!-- vim: fdm=marker:tw=80:ts=4:sw=4:sts=4:et:ai
|
||||
-->
|
56
views/search.tpl
Normal file
56
views/search.tpl
Normal file
|
@ -0,0 +1,56 @@
|
|||
%import re
|
||||
<div id="searchbox">
|
||||
<form action="results" method="get">
|
||||
<table id="form">
|
||||
<tr>
|
||||
<td width="50%">
|
||||
<b>Query</b>
|
||||
<input tabindex="0" type="search" name="query" value="{{query['keywords']}}" autofocus><br><br>
|
||||
<input type="submit" value="Search">
|
||||
<a href=".." tabindex="-1"><input type="button" value="Reset"></a>
|
||||
<a href="settings" tabindex="-1"><input type="button" value="Settings"></a>
|
||||
</td>
|
||||
<td width="30%">
|
||||
<b>Folder</b><br>
|
||||
<select id="folders" name="dir">
|
||||
%for d in sorted(dirs, key=str.lower):
|
||||
%style = "margin-left: %dem" % (2*d.count('/'))
|
||||
%if d in query['dir']:
|
||||
<option style="{{style}}" selected value="{{d}}">{{re.sub('.+/','', d)}}</option>
|
||||
%else:
|
||||
<option style="{{style}}" value="{{d}}">{{re.sub('.+/','', d)}}</option>
|
||||
%end
|
||||
%end
|
||||
</select><br>
|
||||
<b>Dates</b> <small class="gray">YYYY[-MM][-DD]</small><br>
|
||||
<input name="after" value="{{query['after']}}" autocomplete="off"> — <input name="before" value="{{query['before']}}" autocomplete="off">
|
||||
</td>
|
||||
<td>
|
||||
<b>Sort by</b>
|
||||
<select name="sort">
|
||||
%for s in sorts:
|
||||
%if query['sort'] == s[0]:
|
||||
<option selected value="{{s[0]}}">{{s[1]}}</option>
|
||||
%else:
|
||||
<option value="{{s[0]}}">{{s[1]}}</option>
|
||||
%end
|
||||
%end
|
||||
</select><br>
|
||||
<b>Order</b>
|
||||
<select name="ascending">
|
||||
%if int(query['ascending']) == 1:
|
||||
<option value="0">Descending</option>
|
||||
<option value="1" selected>Ascending</option>
|
||||
%else:
|
||||
<option value="0" selected>Descending</option>
|
||||
<option value="1">Ascending</option>
|
||||
%end
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<!-- vim: fdm=marker:tw=80:ts=4:sw=4:sts=4:et:ai
|
||||
-->
|
20
views/settings.tpl
Normal file
20
views/settings.tpl
Normal file
|
@ -0,0 +1,20 @@
|
|||
%include header title="docsearch / settings"
|
||||
<div id="settings-box">
|
||||
<form action="set" method="get">
|
||||
<b>Prefix</b> <small class="gray">(location of documents on local drive)</small>
|
||||
<input name="prefix" value={{prefix}}><br><br>
|
||||
<b>Find similar</b> <small class="gray">(1 or 0, show "squats" and "squatter")</small>
|
||||
<input name="stem" value={{stem}}><br><br>
|
||||
<hr>
|
||||
<b>Context words</b> <small class="gray">(number of words shown in search results)</small>
|
||||
<input name="context" value={{context}}><br><br>
|
||||
<b>Time</b> <small class="gray">(time format string)</small>
|
||||
<input name="timefmt" value={{timefmt}}><br><br>
|
||||
<b>Folder depth</b> <small class="gray">(number of levels of the folder dropdown)</small>
|
||||
<input name="dirdepth" value={{dirdepth}}><br><br>
|
||||
<hr>
|
||||
<input type="submit" value="Save">
|
||||
<a href=".."><input type="button" value="Cancel"></a>
|
||||
</form>
|
||||
</div>
|
||||
%include footer
|
8
webui-standalone.py
Executable file
8
webui-standalone.py
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!env python
|
||||
import bottle
|
||||
import webui
|
||||
|
||||
bottle.debug(True)
|
||||
bottle.run(host='localhost', port=8080, reloader=True)
|
||||
|
||||
# vim: foldmethod=marker:filetype=python:textwidth=80:ts=4:et
|
8
webui-wsgi.py
Executable file
8
webui-wsgi.py
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!env python
|
||||
import os
|
||||
import bottle
|
||||
import webui
|
||||
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
application = bottle.default_app()
|
||||
# vim: foldmethod=marker:filetype=python:textwidth=80:ts=4:et
|
245
webui.py
Executable file
245
webui.py
Executable file
|
@ -0,0 +1,245 @@
|
|||
#!env python
|
||||
#{{{ imports
|
||||
import os
|
||||
import bottle
|
||||
import time
|
||||
import recoll
|
||||
import datetime
|
||||
import glob
|
||||
import hashlib
|
||||
import json
|
||||
import csv
|
||||
import StringIO
|
||||
import ConfigParser
|
||||
import string
|
||||
import shlex
|
||||
from pprint import pprint
|
||||
#}}}
|
||||
#{{{ settings
|
||||
# recoll settings
|
||||
RECOLL_CONFS = [ '~/.recoll/recoll.conf', '/etc/recoll.conf' ]
|
||||
|
||||
# settings defaults
|
||||
DEFAULTS = {
|
||||
'prefix': 'z:/',
|
||||
'context': 30,
|
||||
'stem': 1,
|
||||
'timefmt': '%c',
|
||||
'dirdepth': 3,
|
||||
}
|
||||
|
||||
# sort fields/labels
|
||||
SORTS = [
|
||||
("mtime", "Date",),
|
||||
("url", "Path"),
|
||||
("filename", "Filename"),
|
||||
("relevancyrating", "Relevancy"),
|
||||
("fbytes", "Size"),
|
||||
("author", "Author"),
|
||||
]
|
||||
|
||||
# doc fields
|
||||
FIELDS = [
|
||||
# exposed by python api
|
||||
'ipath',
|
||||
'filename',
|
||||
'title',
|
||||
'author',
|
||||
'fbytes',
|
||||
'dbytes',
|
||||
'size',
|
||||
'fmtime',
|
||||
'dmtime',
|
||||
'mtime',
|
||||
'mtype',
|
||||
'origcharset',
|
||||
'sig',
|
||||
'relevancyrating',
|
||||
'url',
|
||||
'abstract',
|
||||
'keywords',
|
||||
# calculated
|
||||
'time',
|
||||
'snippet',
|
||||
'label',
|
||||
]
|
||||
#}}}
|
||||
#{{{ functions
|
||||
#{{{ helpers
|
||||
def select(ls, invalid=[None]):
|
||||
for value in ls:
|
||||
if value not in invalid:
|
||||
return value
|
||||
|
||||
def timestr(secs, fmt):
|
||||
t = time.gmtime(int(secs))
|
||||
return time.strftime(fmt, t)
|
||||
|
||||
def normalise_filename(fn):
|
||||
valid_chars = "_-%s%s" % (string.ascii_letters, string.digits)
|
||||
out = ""
|
||||
for i in range(0,len(fn)):
|
||||
if fn[i] in valid_chars:
|
||||
out += fn[i]
|
||||
else:
|
||||
out += "_"
|
||||
return out
|
||||
#}}}
|
||||
#{{{ get_config
|
||||
def get_config():
|
||||
config = {}
|
||||
# find recoll.conf
|
||||
for f in RECOLL_CONFS:
|
||||
f = os.path.expanduser(f)
|
||||
if os.path.isfile(f):
|
||||
path = f
|
||||
break
|
||||
# read recoll.conf
|
||||
rc_ini_str = '[main]\n' + open(path, 'r').read()
|
||||
rc_ini_fp = StringIO.StringIO(rc_ini_str)
|
||||
rc_ini = ConfigParser.RawConfigParser()
|
||||
rc_ini.readfp(rc_ini_fp)
|
||||
# parse recoll.conf
|
||||
rc = {}
|
||||
for s in rc_ini.sections():
|
||||
rc[s] = {}
|
||||
for k, v in rc_ini.items(s):
|
||||
rc[s][k] = v
|
||||
# get useful things from recoll.conf
|
||||
config['dirs'] = shlex.split(rc['main']['topdirs'])
|
||||
# get config from cookies or defaults
|
||||
for k, v in DEFAULTS.items():
|
||||
config[k] = select([bottle.request.get_cookie(k), v])
|
||||
return config
|
||||
#}}}
|
||||
#{{{ get_dirs
|
||||
def get_dirs(tops, depth):
|
||||
v = []
|
||||
for top in tops:
|
||||
dirs = [top]
|
||||
for d in range(1, int(depth)+1):
|
||||
dirs = dirs + glob.glob(top + '/*' * d)
|
||||
dirs = filter(lambda f: os.path.isdir(f), dirs)
|
||||
top_path = top.rsplit('/', 1)[0]
|
||||
dirs = [w.replace(top_path+'/', '') for w in dirs]
|
||||
v = v + dirs
|
||||
return ['<all>'] + v
|
||||
#}}}
|
||||
#{{{ get_query
|
||||
def get_query():
|
||||
query = {
|
||||
'keywords': select([bottle.request.query.get('query'), '']),
|
||||
'before': select([bottle.request.query.get('before'), '']),
|
||||
'after': select([bottle.request.query.get('after'), '']),
|
||||
'dir': select([bottle.request.query.get('dir'), '', '<all>'], [None, '']),
|
||||
'sort': select([bottle.request.query.get('sort'), SORTS[0][0]]),
|
||||
'ascending': select([bottle.request.query.get('ascending'), 0]),
|
||||
}
|
||||
return query
|
||||
#}}}
|
||||
#{{{ query_to_recoll_string
|
||||
def query_to_recoll_string(q):
|
||||
qs = q['keywords'].decode('utf-8')
|
||||
if len(q['after']) > 0 or len(q['before']) > 0:
|
||||
qs += " date:%s/%s" % (q['after'], q['before'])
|
||||
if q['dir'] != '<all>':
|
||||
qs += " dir:\"%s\" " % q['dir']
|
||||
return qs
|
||||
#}}}
|
||||
#{{{ recoll_search
|
||||
def recoll_search(q, sort, ascending):
|
||||
config = get_config()
|
||||
tstart = datetime.datetime.now()
|
||||
results = []
|
||||
db = recoll.connect()
|
||||
db.setAbstractParams(contextwords=int(config['context']), maxchars=5000)
|
||||
query = db.query()
|
||||
query.sortby(sort, int(ascending))
|
||||
try:
|
||||
nres = query.execute(q, stemming=int(config['stem']))
|
||||
except:
|
||||
nres = 0
|
||||
for i in range(0, nres):
|
||||
doc = query.fetchone()
|
||||
d = {}
|
||||
for f in FIELDS:
|
||||
d[f] = getattr(doc, f).encode('utf-8')
|
||||
d['label'] = select([d['title'], d['filename'], '?'], [None, ''])
|
||||
d['sha'] = hashlib.sha1(d['url']+d['ipath']).hexdigest()
|
||||
d['time'] = timestr(d['mtime'], config['timefmt'])
|
||||
d['snippet'] = db.makeDocAbstract(doc, query).encode('utf-8')
|
||||
results.append(d)
|
||||
tend = datetime.datetime.now()
|
||||
return results, tend - tstart
|
||||
#}}}
|
||||
#}}}
|
||||
#{{{ routes
|
||||
#{{{ static
|
||||
@bottle.route('/static/:path#.+#')
|
||||
def server_static(path):
|
||||
return bottle.static_file(path, root='./static')
|
||||
#}}}
|
||||
#{{{ main
|
||||
@bottle.route('/')
|
||||
@bottle.view('main')
|
||||
def main():
|
||||
config = get_config()
|
||||
return { 'dirs': get_dirs(config['dirs'], config['dirdepth']),
|
||||
'query': get_query(), 'sorts': SORTS }
|
||||
#}}}
|
||||
#{{{ results
|
||||
@bottle.route('/results')
|
||||
@bottle.view('results')
|
||||
def results():
|
||||
config = get_config()
|
||||
query = get_query()
|
||||
qs = query_to_recoll_string(query)
|
||||
pprint(query)
|
||||
res, timer = recoll_search(qs, query['sort'], query['ascending'])
|
||||
return { 'res': res, 'time': timer, 'query': query, 'dirs':
|
||||
get_dirs(config['dirs'], config['dirdepth']),'qs': qs, 'sorts': SORTS, 'config': config,
|
||||
'query_string': bottle.request.query_string, 'roots': config['dirs'] }
|
||||
#}}}
|
||||
#{{{ json
|
||||
@bottle.route('/json')
|
||||
def get_json():
|
||||
query = get_query()
|
||||
qs = query_to_recoll_string(query)
|
||||
bottle.response.headers['Content-Type'] = 'application/json'
|
||||
bottle.response.headers['Content-Disposition'] = 'attachment; filename=recoll-%s.json' % normalise_filename(qs)
|
||||
res, timer = recoll_search(qs, query['sort'], query['ascending'])
|
||||
|
||||
return json.dumps({ 'query': query, 'results': res })
|
||||
#}}}
|
||||
#{{{ csv
|
||||
@bottle.route('/csv')
|
||||
def get_csv():
|
||||
query = get_query()
|
||||
qs = query_to_recoll_string(query)
|
||||
bottle.response.headers['Content-Type'] = 'text/csv'
|
||||
bottle.response.headers['Content-Disposition'] = 'attachment; filename=recoll-%s.csv' % normalise_filename(qs)
|
||||
res, timer = recoll_search(qs, query['sort'], query['ascending'])
|
||||
si = StringIO.StringIO()
|
||||
cw = csv.writer(si)
|
||||
cw.writerow(FIELDS)
|
||||
for doc in res:
|
||||
row = []
|
||||
for f in FIELDS:
|
||||
row.append(doc[f])
|
||||
cw.writerow(row)
|
||||
return si.getvalue().strip("\r\n")
|
||||
#}}}
|
||||
#{{{ settings/set
|
||||
@bottle.route('/settings')
|
||||
@bottle.view('settings')
|
||||
def settings():
|
||||
return get_config()
|
||||
|
||||
@bottle.route('/set')
|
||||
def set():
|
||||
for k, v in DEFAULTS.items():
|
||||
bottle.response.set_cookie(k, str(bottle.request.query.get(k)), max_age=3153600000)
|
||||
bottle.redirect('..')
|
||||
#}}}
|
||||
#}}}
|
||||
# vim: fdm=marker:tw=80:ts=4:sw=4:sts=4:et
|
Loading…
Add table
Add a link
Reference in a new issue