note description: "Summary description for {ES_CLOUD_ACTIVITIES_HANDLER}." date: "$Date$" revision: "$Revision$" class ES_CLOUD_ACTIVITIES_HANDLER inherit CMS_HANDLER rename make as make_with_cms_api end WSF_URI_TEMPLATE_HANDLER create make feature {NONE} -- Initialization make (a_mod_api: ES_CLOUD_API) do make_with_cms_api (a_mod_api.cms_api) es_cloud_api := a_mod_api end feature -- API es_cloud_api: ES_CLOUD_API feature -- Execution execute (req: WSF_REQUEST; res: WSF_RESPONSE) -- Execute handler for `req' and respond in `res'. do if req.is_get_request_method then process_get (req, res) -- elseif req.is_post_request_method then else send_bad_request (req, res) end end process_get (req: WSF_REQUEST; res: WSF_RESPONSE) local l_active_user, l_license_user, l_user: ES_CLOUD_USER r: like new_generic_response s, sub: STRING l_session: detachable ES_CLOUD_SESSION l_sessions: detachable LIST [ES_CLOUD_SESSION] inst: ES_CLOUD_INSTALLATION l_display_all: BOOLEAN ago: DATE_TIME_AGO_CONVERTER l_can_be_deleted: BOOLEAN l_license: detachable ES_CLOUD_LICENSE l_installations: LIST [ES_CLOUD_INSTALLATION] l_hide_sessions, l_own_data: BOOLEAN do r := new_generic_response (req, res) r.add_javascript_url (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/js/es_cloud.js", Void)) r.add_style (r.module_name_resource_url ({ES_CLOUD_MODULE}.name, "/files/css/es_cloud.css", Void), Void) r.set_title ("Activity") s := "" create ago.make if attached api.user as u then create l_active_user.make (u) end if attached {WSF_STRING} req.path_parameter ("license_key") as p_license_key then l_license := es_cloud_api.license_by_key (p_license_key.value) if l_license /= Void then l_license_user := es_cloud_api.user_for_license (l_license) l_user := l_license_user if l_license_user /= Void and l_active_user /= Void then l_own_data := l_license_user.same_as (l_active_user) end end else l_user := l_active_user l_own_data := l_active_user /= Void end if api.has_permission ({ES_CLOUD_MODULE}.perm_view_any_es_activities) or l_own_data then if l_license /= Void then s.append ("

License " + html_encoded (l_license.plan.title_or_name) + " ") s.append ("") s.append (html_encoded (l_license.key)) s.append ("") if l_license_user /= Void then s.append ("
(account "+ api.html_encoded (api.real_user_display_name (l_license_user)) + ")") end s.append ("

") l_installations := es_cloud_api.license_installations (l_license) elseif l_active_user /= Void then s.append ("

Account "+ api.html_encoded (api.real_user_display_name (l_active_user)) +"

") l_installations := es_cloud_api.user_installations (l_active_user) end -- Plan -- Installation ... s.append ("
") l_display_all := attached req.query_parameter ("display") as d and then d.is_case_insensitive_equal ("all") if l_user /= Void and then l_installations /= Void and then not l_installations.is_empty then if l_license /= Void then s.append ("

EiffelStudio license " + html_encoded (l_license.key) + " is installed on " + l_installations.count.out) if l_installations.count > 1 then s.append (" devices: ") else s.append (" device: ") end else s.append ("

EiffelStudio : installed " + l_installations.count.out + " time(s) ") end if l_display_all then s.append ("only active sessions") else s.append ("include ended or expired") end s.append ("

") s.append ("

") else if l_license /= Void then s.append ("

EiffelStudio license " + html_encoded (l_license.key) + " is not yet installed.

") else s.append ("

EiffelStudio is not yet installed.

") end end s.append ("
") r.set_main_content (s) r.execute else api.response_api.send_access_denied (Void, req, res) end end append_session_to_html (a_title: detachable READABLE_STRING_GENERAL; a_session: ES_CLOUD_SESSION; a_html: STRING_8; ago: DATE_TIME_AGO_CONVERTER) local k: READABLE_STRING_GENERAL s: STRING do a_html.append ("
  • ") if a_title /= Void then s := html_encoded (a_title) elseif attached a_session.title as a_session_title then s := html_encoded (a_session_title) else s := html_encoded (a_session.id) end if s /= Void then s.replace_substring_all ("%N", "
    ") a_html.append (s) end a_html.append (" ") a_html.append (html_encoded (k)) a_html.append ("") a_html.append (" ") ago.append_date_to ("", a_session.first_date, a_html) -- a_html.append (date_time_to_string (a_session.first_date)) a_html.append ("") a_html.append (" ") ago.append_date_to ("", a_session.last_date, a_html) -- a_html.append (date_time_to_string (a_session.last_date)) a_html.append ("") if api.has_permission ({ES_CLOUD_MODULE}.perm_view_any_es_activities) then if attached a_session.data as sess_data then a_html.append ("
    ") a_html.append (html_encoded (sess_data)) a_html.append ("
    %N") end end a_html.append ("
  • ") end note copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end