Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Fix error preventing session creation
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Aug 13, 2021
1 parent 3716eb4 commit f4de02f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
6 changes: 2 additions & 4 deletions source/server/code/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def creator
}
end

# - - - - - - - - - - - - - - - - - - - - -

get '/choose_ltf', provides:[:html] do
respond_to { |wants|
wants.html {
Expand All @@ -79,8 +77,8 @@ def creator
post '/create.json', provides:[:json] do
respond_to { |wants|
wants.json {
id, _ = createByType(json_args)
json({'route':"/creator/enter?id=#{id}"})
_id, url = createByType(json_args)
json({'route' => url})
}
}
end
Expand Down
37 changes: 21 additions & 16 deletions source/server/code/views/choose_custom_problem.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@ $(() => {
$('.type').html(cd.urlParam('type'));

$('button.ok').click(() => {
const name = encodeURIComponent(cd.selectedDisplayName);
$.ajax({
type: 'POST',
url: `/creator/confirm?${cd.urlParams()}&display_name=${name}`,
dataType: 'json',
async: true,
success: (response) => {
if (cd.urlParam('type') === 'group') {
cd.goto(response.route);
} else {
cd.windowOpen(response.route);
$('.home-icon').click();
}
}
});
const name = encodeURIComponent(cd.selectedDisplayName);
const params = cd.urlParams() + `&display_name=${name}`;
$.post('/creator/create.json', toJSON(params), (response) => {
if (cd.urlParam('type') === 'group') {
cd.goto(response.route);
} else {
cd.windowOpen(response.route);
$('.home-icon').click();
}
});
});
});

const toJSON = (s) => { // "x=1&y=2&z=3"
const args = s.split('&'); // [ "x=1", "y=2", "z=3" ]
const elements = args.map((arg) => arg.split('=')); // [ ["x","1"],["y","2"],["z","3"]]
const obj = elements.reduce((m,a) => {
m[a[0]] = decodeURIComponent(a[1]);
return m;
}, {}); // { "x":"1", "y":"2", "z":"3" }
return JSON.stringify(obj); // '{ "x":"1", "y":"2", "z":"3" }'
};

});
</script>

<div id="choose-custom-problem-page">
Expand Down
37 changes: 21 additions & 16 deletions source/server/code/views/choose_ltf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@ $(() => {
$('.type').html(cd.urlParam('type'));

$('button.ok').click(() => {
const name = encodeURIComponent(cd.selectedDisplayName);
$.ajax({
type: 'POST',
url: `/creator/confirm?${cd.urlParams()}&language_name=${name}`,
dataType: 'json',
async: true,
success: (response) => {
if (cd.urlParam('type') === 'group') {
cd.goto(response.route);
} else {
cd.windowOpen(response.route);
$('.home-icon').click();
}
}
});
const name = encodeURIComponent(cd.selectedDisplayName);
const params = cd.urlParams() + `&language_name=${name}`;
$.post('/creator/create.json', toJSON(params), (response) => {
if (cd.urlParam('type') === 'group') {
cd.goto(response.route);
} else {
cd.windowOpen(response.route);
$('.home-icon').click();
}
});
});
});

const toJSON = (s) => { // "x=1&y=2&z=3"
const args = s.split('&'); // [ "x=1", "y=2", "z=3" ]
const elements = args.map((arg) => arg.split('=')); // [ ["x","1"],["y","2"],["z","3"]]
const obj = elements.reduce((m,a) => {
m[a[0]] = decodeURIComponent(a[1]);
return m;
}, {}); // { "x":"1", "y":"2", "z":"3" }
return JSON.stringify(obj); // '{ "x":"1", "y":"2", "z":"3" }'
};

});
</script>

<div id="choose-ltf-page">
Expand Down
4 changes: 2 additions & 2 deletions test/server/create_kata_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def id58_setup

def json_post_create(args)
json_post '/create.json', args
route = json_response['route'] # eg "/creator/enter?id=xCSKgZ"
assert %r"/creator/enter\?id=(?<id>.*)" =~ route, route
route = json_response['route'] # eg "/kata/edit?id=xCSKgZ"
assert %r"/kata/edit\?id=(?<id>.*)" =~ route, route
assert kata_exists?(id), "id:#{id}:" # eg "xCSKgZ"
yield kata_manifest(id)
end
Expand Down

0 comments on commit f4de02f

Please sign in to comment.