From 48aac3bbe1e958e1db4d99717e330ffbe36965dc Mon Sep 17 00:00:00 2001 From: ilin <339966289@mail.ru> Date: Mon, 11 Dec 2017 15:36:03 +0300 Subject: [PATCH 1/2] User preference: Redirect to ticket detail page on service request save #12 --- helpers/firsttimesetup.rb | 3 ++- helpers/webcontext.rb | 1 + routes/auth.rb | 5 +++-- routes/tickets.rb | 6 +++++- routes/usermgt.rb | 11 ++++++++++- views/registeruser.erb | 4 ++++ views/userdetail.erb | 4 ++++ views/userprofile.erb | 6 ++++++ 8 files changed, 35 insertions(+), 5 deletions(-) diff --git a/helpers/firsttimesetup.rb b/helpers/firsttimesetup.rb index f7411f2..a112fe1 100644 --- a/helpers/firsttimesetup.rb +++ b/helpers/firsttimesetup.rb @@ -9,7 +9,8 @@ def appsetup() :rolename => 'admin', :display => 'Administrator', :email => 'root@localhost', - :islocked => 'false' + :islocked => 'false', + :ticket_details => true } @db[:users].insert_one recuser diff --git a/helpers/webcontext.rb b/helpers/webcontext.rb index 3a6f2b7..be98f21 100644 --- a/helpers/webcontext.rb +++ b/helpers/webcontext.rb @@ -8,5 +8,6 @@ def is_user_logged_in def init_ctx @username = session[:username] @rolename = session[:rolename] + @ticket_details = session[:ticket_details] end end \ No newline at end of file diff --git a/routes/auth.rb b/routes/auth.rb index e09f148..8464b2b 100644 --- a/routes/auth.rb +++ b/routes/auth.rb @@ -28,14 +28,15 @@ class Helpdesk < Sinatra::Base session[:rolename] = usr[:rolename] session[:username] = usr[:username] + session[:ticket_details] = usr[:ticket_details] redirect '/' end #Logout the user by clearing session information get '/logout' do #self.init_ctx - session[:username] = session[:rolename] = nil - @username = @rolename = nil + session[:username] = session[:rolename] = session[:ticket_details] = nil + @username = @rolename = session[:ticket_details] = nil redirect '/' end diff --git a/routes/tickets.rb b/routes/tickets.rb index ba6b8b6..d8f4921 100644 --- a/routes/tickets.rb +++ b/routes/tickets.rb @@ -30,7 +30,11 @@ class Helpdesk < Sinatra::Base @params[:myguid] = SecureRandom.uuid @db[:requests].insert_one @params @db.close - redirect '/' + if @ticket_details.nil? || @ticket_details == false + redirect '/tickets-list' + else + redirect '/ticket-detail/'+params[:code] + end end diff --git a/routes/usermgt.rb b/routes/usermgt.rb index 4eae6d8..12f246d 100644 --- a/routes/usermgt.rb +++ b/routes/usermgt.rb @@ -46,6 +46,7 @@ class Helpdesk < Sinatra::Base :email => @params[:email], :phone => @params[:phone], :display => @params[:display], + :ticket_details => @params[:ticket_details] == 'on' ? true : false, :islocked => 'false' } @@ -65,6 +66,7 @@ class Helpdesk < Sinatra::Base recuser[:email] = @params[:email] recuser[:phone] = @params[:phone] recuser[:display] = @params[:display] + recuser[:ticket_details] = @params[:ticket_details] == 'on' ? true : false #recuser[:islocked] = 'false' recuser[:islocked] = @params[:islocked] == 'on' ? 'true' : 'false' @@ -82,6 +84,8 @@ class Helpdesk < Sinatra::Base #TODO: Toss a warning end + session[:ticket_details] = @params[:ticket_details] == 'on' ? true : false + @db.close redirect '/users-list?msg=Saved' end @@ -126,7 +130,7 @@ class Helpdesk < Sinatra::Base @rec = @db[:users].find('username' => @username).limit(1).first - reccnt = @db[:users].find('email' => @params[:email]).count #limit(1).first + reccnt = @db[:users].find('email' => @params[:email], 'username' => {'$ne' => @username}).count #limit(1).first issue post #36 Message displayed "Email+already+exists", but only current record has this email. if reccnt > 0 #!= nil redirect '/userprofile?msg=Email+already+exists' return @@ -138,12 +142,16 @@ class Helpdesk < Sinatra::Base @rec[x] = @params[x] end + @rec[:ticket_details] = @params[:ticket_details] == 'on' ? true : false + @db[:users].update_one( {'username' => @username}, @rec, {:upsert => false} ) + session[:ticket_details] = @rec[:ticket_details] + redirect '/userprofile?msg=Saved' end @@ -179,6 +187,7 @@ class Helpdesk < Sinatra::Base :email => @params[:email], :phone => @params[:phone], :display => @params[:display], + :ticket_details => @params[:ticket_details] == 'on' ? true : false, :islocked => 'false' } diff --git a/views/registeruser.erb b/views/registeruser.erb index 16ae670..5d433f0 100644 --- a/views/registeruser.erb +++ b/views/registeruser.erb @@ -32,6 +32,10 @@ +
+ + +
diff --git a/views/userdetail.erb b/views/userdetail.erb index 337d57d..72066e0 100644 --- a/views/userdetail.erb +++ b/views/userdetail.erb @@ -37,6 +37,10 @@ style="margin-left: 20px" /> +
+ + style="margin-left: 20px" /> +
diff --git a/views/userprofile.erb b/views/userprofile.erb index 12f7a6f..3e1e9c9 100644 --- a/views/userprofile.erb +++ b/views/userprofile.erb @@ -33,6 +33,12 @@ fields = { <% end %> + +
+ + style="margin-left: 20px" /> +
+
Change Password From b992723c22a9191e48e4a61f543d680c122b7cad Mon Sep 17 00:00:00 2001 From: ilin <339966289@mail.ru> Date: Tue, 12 Dec 2017 11:55:49 +0300 Subject: [PATCH 2/2] Part Add is buggy #35 --- routes/tickets.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/tickets.rb b/routes/tickets.rb index d8f4921..0c23607 100644 --- a/routes/tickets.rb +++ b/routes/tickets.rb @@ -332,7 +332,7 @@ class Helpdesk < Sinatra::Base return #Is a return absolutely necessary? end - check_existing = @rec[:parts].find { |x| x[:part] == @params[:code] } + check_existing = @rec[:parts] == nil ? nil : @rec[:parts].find { |x| x[:part] == @params[:code] } if check_existing != nil #redirect '/' redirect '/ticket-detail/'+@params[:ticket]+'?msg=Part+already+exists'