Skip to content

Commit bb4a343

Browse files
committed
Uses Ajax to create the application in the Wizard.
1 parent beff485 commit bb4a343

File tree

4 files changed

+90
-6
lines changed

4 files changed

+90
-6
lines changed

src/Server/Coderr.Server.SqlServer/Core/Applications/Queries/GetApplicationIdByKeyHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public async Task<GetApplicationIdByKeyResult> HandleAsync(IMessageContext conte
2222
{
2323
cmd.CommandText = "SELECT Id FROM Applications WHERE AppKey = @appKey";
2424
cmd.AddParameter("appKey", query.ApplicationKey);
25-
return new GetApplicationIdByKeyResult {Id = (int) await cmd.ExecuteScalarAsync()};
25+
var result = await cmd.ExecuteScalarAsync();
26+
if (result == null)
27+
return null;
28+
29+
return new GetApplicationIdByKeyResult {Id = (int)result };
2630
}
2731
}
2832
}

src/Server/Coderr.Server.Web/Controllers/AccountController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model)
301301
}
302302

303303

304+
[Authorize]
304305
public async Task<ActionResult> UpdateSession(string returnUrl = null)
305306
{
306307
var getApps = new GetApplicationList { AccountId = User.GetAccountId() };

src/Server/Coderr.Server.Web/Views/Wizard/Application.cshtml

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
{
2323
<p>It's time to create an application. "Application", in codeRR language, means an error reporting entity. </p>
2424
<p>
25-
If you have a client/server based product named "l33tApp" you would typically create two applications in codeRR:
26-
25+
If you have a client/server based product named "l33tApp" you would typically create two applications in codeRR:
26+
2727
</p>
2828
<ul>
2929
<li>l33tApp Client</li>
@@ -35,16 +35,90 @@
3535
Specify the name of your first application, you'll be able to add more applications later.
3636
</p>
3737
}
38-
<form method="post">
38+
<form method="post" id="createMyAppForm">
3939
<div class="form-group">
4040
<input type="text" name="Name" placeholder="Application name" class="form-control" />
4141
</div>
4242
<div class="form-group">
4343
<button type="submit" class="btn btn-primary">Create</button>
44-
<a href="http://discuss.coderrapp.com" target="_self">Help</a> |
44+
<a href="http://discuss.coderrapp.com" target="_self">Help</a> |
4545
<a href="@Url.Content("~/")#/">Exit wizard</a>
4646
</div>
4747
</form>
4848
</div>
4949
</div>
50-
</div>
50+
</div>
51+
52+
@section scripts
53+
{
54+
<script>
55+
function createMyApplication(name, callback) {
56+
var hostType = 'DesktopApplication';
57+
58+
var client = new Griffin.Net.HttpClient();
59+
client.get(window.API_URL + '/guid')
60+
.done(function (response) {
61+
var appKey = response.body;
62+
var cmd = new codeRR.Core.Applications.Commands.CreateApplication(name, hostType);
63+
cmd.ApplicationKey = appKey;
64+
Griffin.Cqs.CqsClient.command(cmd)
65+
.done(function () {
66+
callback(appKey);
67+
})
68+
.fail(function (rejection) {
69+
console.log(rejection.message);
70+
});
71+
});
72+
}
73+
74+
function checkForApplication(appKey, foundCallback, notFoundCallback) {
75+
var query = new codeRR.Core.Applications.Queries.GetApplicationIdByKey(appKey);
76+
Griffin.Cqs.CqsClient.query(query)
77+
.done(function (result) {
78+
console.log(result);
79+
if (result != null) {
80+
foundCallback(result);
81+
} else {
82+
notFoundCallback();
83+
}
84+
85+
//$('#appName').val('');
86+
//var appUrl = '#/application/' + result.Id + '/';
87+
//window.location = window.WEB_SITE + '/account/UpdateSession?returnUrl=' + encodeURIComponent(window.WEB_ROOT + appUrl);
88+
});
89+
}
90+
91+
var timer = null;
92+
var attemptsLeft = 5;
93+
$('#createMyAppForm').submit(function(e) {
94+
e.preventDefault();
95+
var name = $('input[name="Name"]', this).val();
96+
createMyApplication(name,
97+
function (appKey) {
98+
timer = setInterval(function() {
99+
100+
checkForApplication(appKey,
101+
function(app) {
102+
clearInterval(timer);
103+
var nextPage = '@Url.Content("~/#/application/")' + app.Id + '/';
104+
if (@ViewBag.FirstApplication.ToString().ToLower() == false) {
105+
nextPage = '@Url.Action("Packages")?applicationId=' + app.Id;
106+
}
107+
window.location = '@Url.Content("~/account/UpdateSession")?returnUrl=' +
108+
encodeURIComponent(nextPage);
109+
},
110+
function() {
111+
attemptsLeft--;
112+
if (attemptsLeft <= 0) {
113+
clearInterval(timer);
114+
humane.log('Failed to create application :(');
115+
}
116+
});
117+
},
118+
500);
119+
120+
});
121+
});
122+
123+
</script>
124+
}

src/Server/Coderr.Server.Web/Views/Wizard/_Layout.cshtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
88
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/css/tether.min.css" />
99
<link rel="stylesheet" href="@Url.Content("~/Content/bootstrap.min.css")">
10+
<script>
11+
window.API_URL = '@ApiUrl';
12+
</script>
1013
@Styles.Render("~/Content/css")
1114
@RenderSection("css", false)
1215
<style>
@@ -23,6 +26,8 @@
2326
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
2427
@Scripts.Render("~/bundles/jquery")
2528
@Scripts.Render("~/bundles/app")
29+
<script src="@Url.Content("~/Scripts/Promise.js")"></script>
30+
<script src="@Url.Content("~/Scripts/CqsClient.js")"></script>
2631
@RenderSection("scripts", false)
2732
</body>
2833
</html>

0 commit comments

Comments
 (0)