Skip to content

Commit

Permalink
Merge pull request #37 from IlinDmitry/master
Browse files Browse the repository at this point in the history
User preference: Redirect to ticket detail page on service request save #12
  • Loading branch information
redknitin authored Dec 12, 2017
2 parents ffd4545 + b992723 commit 7c7ac9f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion helpers/firsttimesetup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions helpers/webcontext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions routes/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions routes/tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -328,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'
Expand Down
11 changes: 10 additions & 1 deletion routes/usermgt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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'
}

Expand Down
4 changes: 4 additions & 0 deletions views/registeruser.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<label>Display Name</label>
<input name="display" id="field_display" type="text" class="form-control" />
</div>
<div class="form-group">
<label>Add ticket details after saving</label>
<input name="ticket_details" type="checkbox" class="form-control" />
</div>
</div>
<div class="col-6">
</div>
Expand Down
4 changes: 4 additions & 0 deletions views/userdetail.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<label>Is Locked</label>
<input type="checkbox" name="islocked" <%= @rec[:islocked] == 'false' ? '' : ' checked="checked"' %> style="margin-left: 20px" />
</div>
<div class="form-group">
<label>Add ticket details after saving</label>
<input type="checkbox" name="ticket_details" <%= @rec[:ticket_details] == false || @rec[:ticket_details].nil? ? '' : ' checked="checked"' %> style="margin-left: 20px" />
</div>
</div>
<div class="col-6">
</div>
Expand Down
6 changes: 6 additions & 0 deletions views/userprofile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ fields = {
</div>
<% end %>


<div class="form-group">
<label>Add ticket details after saving</label>
<input type="checkbox" name="ticket_details" <%= @rec[:ticket_details] == false || @rec[:ticket_details].nil? ? '' : ' checked="checked"' %> style="margin-left: 20px" />
</div>

<div style="margin-top: 20px">
<input type="submit" value="Save" class="btn btn-primary" style="margin-right: 8px">
<a href="/change-password" class="btn btn-secondary">Change Password</a>
Expand Down

0 comments on commit 7c7ac9f

Please sign in to comment.