Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
[#828] Pull courses to Nation (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirojdyola authored and lmmrssa committed Jun 21, 2017
1 parent b1f1242 commit 799ed40
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 9 deletions.
94 changes: 90 additions & 4 deletions app/nation/app/views/PullNations.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,91 @@ $(function() {
}),
async: false,
success: function (response) {
alert(App.languageDictValue.attributes.Added_Success);
App.stopActivityIndicator();
//get StepID from coursestep
$.ajax({
url: 'http://'+ admin_name + ':oleoleole@' + nationUrl + '/coursestep/_design/bell/_view/GetCourseStepByCourseID?include_docs=true&key="'+ doc_id +'"',
type: 'GET',
dataType: 'jsonp',
success: function (response) {
if(response.rows.length > 0){
var jsonStepData = [];
for( var i = 0; i < response.rows.length; i++){
jsonStepData.push(response.rows[i].id);
}
//replicate coursetep
$.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8'
},
type: 'POST',
url: '/_replicate',
dataType: 'json',
data: JSON.stringify({
"source": 'http://' + nationUrl + '/coursestep',
"target": 'coursestep',
'doc_ids': jsonStepData
}),
async: false,
success: function (response) {
//get question from coursequestion
$.ajax({
url: 'http://'+ admin_name + ':oleoleole@' + nationUrl + '/coursequestion/_design/bell/_view/GetCourseQuestionByStepID?include_docs=true&keys='+ JSON.stringify(jsonStepData) ,
type: 'GET',
dataType: 'jsonp',
success: function (response) {
if(response.rows.length > 0){
var jsonQuestionData = [];
for( var i = 0; i < response.rows.length; i++){
jsonQuestionData.push(response.rows[i].id);
}
//replicate coursequestion
$.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8'
},
type: 'POST',
url: '/_replicate',
dataType: 'json',
data: JSON.stringify({
"source": 'http://' + nationUrl + '/coursequestion',
"target": 'coursequestion',
'doc_ids': jsonQuestionData
}),
async: false,
success: function (response) {
//after replicated
alert(App.languageDictValue.attributes.Added_Success);
App.stopActivityIndicator();
},
error: function(status) {
console.log(status);
}
});
}else{
alert(App.languageDictValue.attributes.Added_Success);
App.stopActivityIndicator();
}
},
error: function(status) {
console.log(status);
}
});
},
error: function(status) {
console.log(status);
}
});
}else{
alert(App.languageDictValue.attributes.Added_Success);
App.stopActivityIndicator();
}
},
error: function(status) {
console.log(status);
}
});
},
error: function(status) {
console.log(status);
Expand All @@ -249,7 +332,6 @@ $(function() {
console.log(status);
}
});
App.stopActivityIndicator();
}
}
},
Expand Down Expand Up @@ -300,7 +382,11 @@ $(function() {
console.log(response);
if(response.rows.length > 0){
var doc = response.rows[0].doc;
var schedule = doc.startDate + ' | ' +doc.startTime;
var schedule = "";
if(doc.startTime != "")
schedule = doc.startDate + ' | ' +doc.startTime;
else
schedule = doc.startDate;
$('dd#name').html(doc.CourseTitle);
$('dd#subjectLevel').html(doc.subjectLevel);
$('dd#gradeLevel').html(doc.gradeLevel);
Expand Down
10 changes: 5 additions & 5 deletions app/nation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ <h2>
</div>
</div>
<div class="container">
<div class="modal fade" id="modalResources" role="dialog">
<div class="modal fade" id="modalResources" role="dialog" aria-hidden="true" style="display: none; margin-top: 100px;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -1261,7 +1261,7 @@ <h4 class="modal-title"><%= languageDict.attributes.Resource_Detail %></h4>
</div>
</div>
</div>
<div class="modal fade" id="modalCourses" role="dialog">
<div class="modal fade" id="modalCourses" role="dialog" aria-hidden="true" style="display: none; margin-top: 100px;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -1270,9 +1270,9 @@ <h4 class="modal-title"><%= languageDict.attributes.Course_Details %></h4>
</div>
<div class="modal-body">
<dl class="dl-horizontal">
<dt><%= languageDict.attributes.Name %>Name</dt><dd id="name"></dd>
<dt><%= languageDict.attributes.Subject_Level %>Subject Level</dt><dd id="subjectLevel"></dd>
<dt><%= languageDict.attributes.Grade_Level %>Grade Level</dt><dd id="gradeLevel"></dd>
<dt><%= languageDict.attributes.Name %></dt><dd id="name"></dd>
<dt><%= languageDict.attributes.Subject_Level %></dt><dd id="subjectLevel"></dd>
<dt><%= languageDict.attributes.Grade_Level %></dt><dd id="gradeLevel"></dd>
<dt><%= languageDict.attributes.Description %></dt><dd id="description"></dd>
<dt><%= languageDict.attributes.Schedule %></dt><dd id="schedule"></dd>
<dt><%= languageDict.attributes.Location %></dt><dd id="location"></dd>
Expand Down
7 changes: 7 additions & 0 deletions databases/coursequestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ ddoc.views = {
emit(doc._id, true);
}
}
},
GetCourseQuestionByStepID: {
map: function(doc) {
if (doc && doc.stepId) {
emit(doc.stepId, doc._id);
}
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions databases/coursestep.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ ddoc.views = {
}
}
},
GetCourseStepByCourseID: {
map: function(doc) {
if (doc && doc.courseId) {
emit(doc.courseId, doc._id);
}
}
}
}

module.exports = ddoc;

0 comments on commit 799ed40

Please sign in to comment.