aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
Diffstat (limited to 'captain')
-rw-r--r--captain/example/static/style.css15
-rw-r--r--captain/requtils.f90126
-rw-r--r--captain/web.f9056
3 files changed, 176 insertions, 21 deletions
diff --git a/captain/example/static/style.css b/captain/example/static/style.css
index 0a7a556..6af0d2e 100644
--- a/captain/example/static/style.css
+++ b/captain/example/static/style.css
@@ -67,6 +67,7 @@ body {
.joblist {
list-style-type: none;
+ padding-left:15px;
}
.job_result_listitem {
@@ -91,6 +92,20 @@ body {
background-color: #ffc;
}
+.pager {
+ text-align: center;
+ width: 300px;
+ margin-top: 5px;
+ margin-bottom: 5px;
+ padding-top: 3px;
+ padding-bottom: 3px;
+ padding-left: 10px;
+ padding-right: 10px;
+ background-color: #ddd;
+ margin-left:15px;
+}
+
+
@media only screen and (max-width: 590px) {
.heading h1 {
display:none;
diff --git a/captain/requtils.f90 b/captain/requtils.f90
index d2ffb29..1af605f 100644
--- a/captain/requtils.f90
+++ b/captain/requtils.f90
@@ -186,6 +186,132 @@ contains
end function request_static
+ function build_link(link, label, gemini_mode) result(res)
+ implicit none
+
+ character(*), intent(in)::link, label
+ logical, intent(in)::gemini_mode
+ character(len=:), pointer::res
+ integer::nl
+
+ if(gemini_mode) then
+
+ nl = len_trim(link) + len_trim(label) + len('=> ')
+ allocate(character(len=nl)::res)
+ res = '=> '//trim(link)//' '//trim(label)
+
+ else
+
+ nl = len_trim(link) + len_trim(label) + len('<a href=""></a>')
+ allocate(character(len=nl)::res)
+ res = '<a href="'//trim(link)//'">'//trim(label)//'</a>'
+
+ end if
+
+ end function build_link
+
+ function generate_simple_pager(startindex, stopindex, step, maxcount, page, gemini_mode) result(res)
+ use logging
+ implicit none
+
+ integer, intent(in)::startindex, stopindex, step, maxcount
+ character(*), intent(in)::page
+ logical, intent(in)::gemini_mode
+ character(len=:), pointer::res
+
+ integer::i
+ character(len=:), allocatable::back_page, forward_page
+ character(len=:), pointer::back_link, forward_link
+ character(5)::num
+ integer::res_size
+
+ res_size = 128
+
+ back_link => null()
+ forward_link => null()
+
+ if(startindex > 1) then
+ i = max(startindex-step, 1)
+ allocate(character(len=(len_trim(page)+6)) :: back_page)
+ write(num, '(I5)') i
+ num = adjustl(num)
+ back_page = trim(page)//"?"//trim(num)
+ back_link => build_link(back_page, "Newer", gemini_mode)
+ deallocate(back_page)
+ end if
+
+ if(stopindex < maxcount) then
+ i = stopindex+1
+ allocate(character(len=(len_trim(page)+6)) :: forward_page)
+ write(num, '(I5)') i
+ num = adjustl(num)
+ forward_page = trim(page)//"?"//trim(num)
+ forward_link => build_link(forward_page, "Older", gemini_mode)
+ deallocate(forward_page)
+ end if
+
+ if(.not. associated(back_link) .and. .not. associated(forward_link)) then
+
+ res => null()
+
+ else
+
+ if(gemini_mode) then
+ res_size = 1
+ else
+ res_size = len('<p class="pager"> - </p>')
+ end if
+
+ if(associated(back_link)) then
+ res_size = res_size + len(back_link)
+ end if
+ if(associated(forward_link)) then
+ res_size = res_size + len(forward_link)
+ end if
+
+ allocate(character(len=res_size) :: res)
+ res = " "
+
+ if(gemini_mode) then
+
+ if(associated(back_link)) then
+ res = back_link
+ deallocate(back_link)
+ end if
+
+ if(associated(forward_link)) then
+ if(len_trim(res) > 0) then
+ res = trim(res)//new_line(' ')//forward_link
+ else
+ res = forward_link
+ end if
+ deallocate(forward_link)
+ end if
+
+ else
+
+ if(associated(back_link)) then
+ res = '<p class="pager">'//back_link
+ deallocate(back_link)
+ end if
+
+ if(associated(forward_link)) then
+ if(len_trim(res) > 0) then
+ res = trim(res)//" - "//forward_link
+ else
+ res = '<p class="pager">'//forward_link
+ end if
+ deallocate(forward_link)
+ end if
+
+ res = trim(res)//"</p>"
+
+ end if
+
+ end if
+
+ end function generate_simple_pager
+
function render_jobs_links(jobs, startindex, stopindex, gemini_mode, link_prefix) result(res)
use captain_db
implicit none
diff --git a/captain/web.f90 b/captain/web.f90
index c76e053..638e0c3 100644
--- a/captain/web.f90
+++ b/captain/web.f90
@@ -54,23 +54,20 @@ contains
end subroutine build_request_object
function html_link(link, label) result(res)
+ use request_utils, only: build_link
implicit none
character(*), intent(in)::link, label
character(len=:), pointer::res
- integer::nl
-
- nl = len_trim(link) + len_trim(label) + len('<a href=""></a>')
- allocate(character(len=nl)::res)
- res = '<a href="'//trim(link)//'">'//trim(label)//'</a>'
+ res => build_link(link, label, .false.)
end function html_link
function generate_one_instuction_html(req) result(res)
use captain_db
use server_response
- use request_utils, only: get_status_utf8, render_jobs_links
+ use request_utils, only: get_status_utf8, render_jobs_links, generate_simple_pager
implicit none
type(request)::req
@@ -81,9 +78,9 @@ contains
type(job), dimension(:), pointer::jobs
integer, dimension(:), pointer::players
character(len=PLAYER_NAME_LENGTH), dimension(:), pointer::all_players
- integer::i, j, n_jobs, n_players, nsize
+ integer::i, j, n_jobs, n_players, nsize, job_start_index
- character(len=:), pointer::job_link_text, one_link
+ character(len=:), pointer::job_link_text, one_link, pager
character(1)::nl = new_line(' ')
character(PLAYER_NAME_LENGTH)::player_name
character(4)::player_status
@@ -95,11 +92,24 @@ contains
jobs => get_jobs_for_instruction(id_from_req)
if(associated(jobs)) then
+
+ if(associated(req%query_string)) then
+ read(req%query_string, *) job_start_index
+ else
+ job_start_index = 1
+ end if
+
n_jobs = size(jobs)
- job_link_text => render_jobs_links(jobs, gemini_mode=.false., link_prefix="../")
+ job_link_text => render_jobs_links(jobs, gemini_mode=.false., &
+ link_prefix="../", startindex=job_start_index, &
+ stopindex=min(job_start_index+4, n_jobs))
+
else
+
+ job_start_index = 0
n_jobs = 0
job_link_text => null()
+
end if
players => get_instruction_players(id_from_req)
@@ -155,8 +165,18 @@ contains
if(n_jobs == 0) then
res = trim(res)//nl//"None Yet"
else
+
+ pager => generate_simple_pager(job_start_index, job_start_index + 4, 5, n_jobs, req%page,.false.)
+
res = trim(res)//nl//job_link_text
+
+ if(associated(pager)) then
+ res = trim(res)//nl//pager
+ deallocate(pager)
+ end if
+
deallocate(job_link_text)
+
end if
all_players => get_player_names()
@@ -479,7 +499,7 @@ contains
function generate_jobs_html(req) result(res)
use captain_db
use server_response
- use request_utils, only: render_jobs_links
+ use request_utils, only: render_jobs_links, generate_simple_pager
use logging
implicit none
@@ -489,8 +509,7 @@ contains
integer::n, nsize
integer::i_start_jobs, ierr
- character(len=:), pointer::linklist
- character(10)::pager
+ character(len=:), pointer::linklist, pager
n = get_jobs_count()
if(n == 0) then
@@ -522,16 +541,11 @@ contains
res = trim(res)//new_line(' ')//trim(linklist)
! Pagers
- res = trim(res)//new_line(' ')//"<p>"
- if(i_start_jobs /= 1) then
- write(pager, '(I8)') max(i_start_jobs - 15, 1)
- res = trim(res)//'<a href="jobs.html?'//trim(adjustl(pager))//'">&lt;&lt; Newer</a> |'
- end if
- if(i_start_jobs+14 < n) then
- write(pager, '(I8)') i_start_jobs + 15
- res = trim(res)//' <a href="jobs.html?'//trim(adjustl(pager))//'">Older &gt;&gt;</a>'
+ pager => generate_simple_pager(i_start_jobs, min(i_start_jobs+14, n), 15, n, req%page, .false.)
+ if(associated(pager)) then
+ res = trim(res)//new_line(' ')//pager
+ deallocate(pager)
end if
- res = trim(res)//"</p>"
deallocate(linklist)