From 20091904b7bf4b2074b45e25c7eee0e56d19348b Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Mon, 21 Jun 2021 11:04:31 -0400 Subject: Groups of instructions are now supported, allowing launching multiple jobs at once --- captain/web.f90 | 251 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 248 insertions(+), 3 deletions(-) (limited to 'captain/web.f90') diff --git a/captain/web.f90 b/captain/web.f90 index ccd3df0..9254658 100644 --- a/captain/web.f90 +++ b/captain/web.f90 @@ -253,7 +253,7 @@ contains character(len=:), pointer::one_player, scanlink - n = get_instuctions_count() + n = get_instructions_count() if(n == 0) then @@ -291,6 +291,227 @@ contains deallocate(scanlink) end function generate_instructions_html + + function generate_groups_html(req) result(res) + use captain_db + use server_response, only:request + implicit none + + type(request)::req + character(len=:), pointer::res + integer, dimension(:), pointer::groups + character(128)::one_group + integer::n, i + + character(len=:), pointer::one_link + + n = get_group_count_db() + + if(n == 0) then + + allocate(character(len=1024) :: res) + res = "None Yet" + + else + + allocate(character(len=(n*(256+64) + 384)) :: res) + + res = "

Groups

"//new_line(' ')//"" + deallocate(groups) + + end if + + res = trim(res)//new_line(' ')//"

Management

" + + res = trim(res)//new_line(' ')// & + '
'// & + '
' + + end function generate_groups_html + + function generate_one_group_html(req) result(res) + use captain_db + use server_response, only:request + use request_utils + use query_utilities + use logging + use remote_launch, only: launch_group + implicit none + + type(request)::req + character(len=:), pointer::res + + type(query)::q + + character(128)::group_name, instruction_name, player_name + integer::id + + type(group_entry), dimension(:), pointer::entries + type(work_pair), dimension(:), pointer::all_entries + character(len=:), pointer::one_link, delete_link, play_link, qreq + + character(128)::launch_msg + + integer::i, j, n_instructions_group, n_instructions_total + + call req%path_component(2, group_name) + i = index(group_name, ".html") + group_name(i:128) = ' ' + + id = get_group_id_db(trim(group_name)) + entries => null() + all_entries => null() + + launch_msg = " " + + if(associated(req%query_string)) then + + call q%init(req%query_string) + qreq => q%get_value("add") + + if(associated(qreq)) then + + call write_log("ADD: "//trim(qreq)) + + i = index(qreq, ',') + player_name = qreq(i+1:len_trim(qreq)) + instruction_name = qreq(1:i-1) + + i = get_instruction_id(trim(instruction_name)) + j = get_player_id(trim(player_name)) + + call add_entry_to_group_db(id, i, j) + + deallocate(qreq) + + else + + qreq => q%get_value("delete") + + if(associated(qreq)) then + + i = index(qreq, ',') + player_name = qreq(i+1:len(qreq)) + instruction_name = qreq(1:i-1) + + i = get_instruction_id(trim(instruction_name)) + j = get_player_id(trim(player_name)) + + call remove_entry_from_group_db(id, i, j) + + deallocate(qreq) + + else if(trim(req%query_string) == "launch") then + + call launch_group(id) + write(launch_msg, '(I4, 1X, A13)') get_group_entries_count_db(id), "jobs launched" + + else if(trim(req%query_string) == "destroy") then + + call delete_group_db(id) + + end if + + end if + + call q%destroy() + + end if + + n_instructions_group = get_group_entries_count_db(id) + n_instructions_total = get_available_count_db() + + allocate(character( len=(n_instructions_total*384 + 512) ) :: res) + + res = "

"//trim(group_name)//"

" + + if(n_instructions_group == 0) then + + res = trim(res)//new_line(' ')//"

Contains no instructions.

" + + else + + if(len_trim(launch_msg) > 0) then + res = trim(res)//new_line(' ')//'

'//trim(launch_msg)//'

' + else + res = trim(res)//new_line(' ')//'

🚀 Launch Now

' + end if + + res = trim(res)//new_line(' ')//"

Work to Be Performed

"//new_line(' ')//"" + + end if + + if(n_instructions_total > 0) then + + res = trim(res)//new_line(' ')//"

Add Instructions

" + + all_entries => get_available_work_pairs_db() + if(associated(all_entries)) then + + res = trim(res)//new_line(' ')//'
'// & + ''//new_line(' ')// & + ''//'
' + end if + end if + + res = trim(res)//new_line(' ')//'

Destroy This Group

'//new_line(' ')// & + '

💣 Destroy

'//new_line(' ')// & + '

This operation will not destroy any instructions

' + + end function generate_one_group_html function generate_players_html() result(res) use captain_db @@ -694,7 +915,19 @@ contains call page%assign('title', trim(job_page_title)) contents => generate_one_job_html(req) call page%assign('contents', contents) - + + else if(trim(req%location) == "/groups.html") then + + call page%assign('title', 'Instruction Groups') + contents => generate_groups_html(req) + call page%assign('contents', contents) + + else if(trim(first) == "groups") then + + call page%assign('title', 'Instruction Group') + contents => generate_one_group_html(req) + call page%assign('contents', contents) + else call page%assign('title', 'Not Found') @@ -716,7 +949,7 @@ contains end function request_templated function handle_post(req) result(resp) - use captain_db, only: add_player_db + use captain_db, only: add_player_db, add_group_db use page_template use config, only: template_filepath use logging @@ -757,6 +990,18 @@ contains end if + else if(trim(category) == "groups") then + + call req%path_component(2, second) + + ! Add a group + if(trim(second) == "add.html") then + + call add_group_db(posted%get_value("name")) + call page%assign('destination', 'groups.html') + + end if + end if ! Handle the template -- cgit v1.2.3