Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange

This commit is contained in:
guange 2016-07-15 14:50:21 +08:00
commit fff6f4b310
4 changed files with 160 additions and 24 deletions

View File

@ -8,13 +8,23 @@ module Mobile
desc '获取所有课件' desc '获取所有课件'
params do params do
requires :token, type: String requires :token, type: String
requires :page, type: Integer
end end
get do post do
authenticate! authenticate!
page = params[:page] ? params[:page] : 0
rs = ResourcesService.new rs = ResourcesService.new
# data = current_user.course_attachments # data = current_user.course_attachments
data = rs.all_course_attachments current_user data = rs.all_course_attachments current_user
all_count = data.count
data = data.limit(10).offset(page * 10)
count = data.count
present :data, data, with: Mobile::Entities::Attachment,user: current_user present :data, data, with: Mobile::Entities::Attachment,user: current_user
present :all_count, all_count
present :count, count
present :page, page
present :status, 0 present :status, 0
end end
@ -24,14 +34,24 @@ module Mobile
desc '获取所有作业' desc '获取所有作业'
params do params do
requires :token, type: String requires :token, type: String
requires :page, type: Integer
end end
get 'homeworks' do post 'homeworks' do
authenticate! authenticate!
page = params[:page] ? params[:page] : 0
rs = ResourcesService.new rs = ResourcesService.new
homeworks = rs.all_homework_commons current_user homeworks = rs.all_homework_commons current_user
all_count = homeworks.count
homeworks = homeworks.limit(10).offset(page * 10)
count = homeworks.count
present :data, homeworks, with: Mobile::Entities::Homework,user: current_user present :data, homeworks, with: Mobile::Entities::Homework,user: current_user
present :all_count, all_count
present :count, count
present :page, page
present :status, 0 present :status, 0
end end
@ -39,13 +59,23 @@ module Mobile
desc '获取所有测验' desc '获取所有测验'
params do params do
requires :token, type: String requires :token, type: String
requires :page, type: Integer
end end
get 'exercies' do post 'exercises' do
authenticate! authenticate!
page = params[:page] ? params[:page] : 0
rs = ResourcesService.new rs = ResourcesService.new
exercises = rs.all_exercises current_user exercises = rs.all_exercises current_user
all_count = exercises.count
exercises = exercises.limit(10).offset(page * 10)
count = exercises.count
present :data, exercises, with: Mobile::Entities::Exercise,user: current_user present :data, exercises, with: Mobile::Entities::Exercise,user: current_user
present :all_count, all_count
present :count, count
present :page, page
present :status, 0 present :status, 0
end end

View File

@ -24,6 +24,9 @@
<div ng-class="{'undis': !showResources}"> <div ng-class="{'undis': !showResources}">
<div ng-repeat="r in resources|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/courseware.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.filename}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2" ng-click="sendFile(r)">发送</a><div class="cl"></div></div> <div ng-repeat="r in resources|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/courseware.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.filename}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2" ng-click="sendFile(r)">发送</a><div class="cl"></div></div>
<div ng-if="has_more">
<div id="more" class="more-events mt10" ng-click="loadResourceData(1,page+1);">更多</div>
</div>
<p ng-show="resources_tag == true && resources.length<=0" class="class-test-tip">暂无课件,<br /> <p ng-show="resources_tag == true && resources.length<=0" class="class-test-tip">暂无课件,<br />
请登录Trustie网站在PC浏览器中上传课件。</p> 请登录Trustie网站在PC浏览器中上传课件。</p>
</div> </div>
@ -43,6 +46,9 @@
<div ng-class="{'undis': !showHomework}"> <div ng-class="{'undis': !showHomework}">
<div ng-repeat="r in homeworks|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/homework.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.homework_name}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2 undis" ng-click="sendFile(r)">发送</a><div class="cl"></div></div> <div ng-repeat="r in homeworks|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/homework.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.homework_name}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2 undis" ng-click="sendFile(r)">发送</a><div class="cl"></div></div>
<div ng-if="homework_has_more">
<div id="homework_more" class="more-events mt10" ng-click="loadResourceData(2,page+1);">更多</div>
</div>
<p ng-show="homeworks_tag == true && homeworks.length<=0" class="class-test-tip">暂无作业,<br /> <p ng-show="homeworks_tag == true && homeworks.length<=0" class="class-test-tip">暂无作业,<br />
请登录Trustie网站在PC浏览器中上传作业。</p> 请登录Trustie网站在PC浏览器中上传作业。</p>
@ -50,6 +56,9 @@
<div ng-class="{'undis': !showTestcase}"> <div ng-class="{'undis': !showTestcase}">
<div ng-repeat="r in exercises|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/test.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.exercise_name}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2 undis" ng-click="sendFile(r)">发送</a><div class="cl"></div></div> <div ng-repeat="r in exercises|filter:searchText" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/test.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.exercise_name}}</span><a ng-show="isTeacher" herf="javascript:void(0);" class="fr mr10 link-blue2 undis" ng-click="sendFile(r)">发送</a><div class="cl"></div></div>
<div ng-if="exercise_has_more">
<div id="exercise_more" class="more-events mt10" ng-click="loadResourceData(3,page+1);">更多</div>
</div>
<p ng-show="exercises_tag == true && exercises.length<=0" class="class-test-tip">暂无小测验,<br /> <p ng-show="exercises_tag == true && exercises.length<=0" class="class-test-tip">暂无小测验,<br />
请登录Trustie网站在PC浏览器中上传小测验。</p> 请登录Trustie网站在PC浏览器中上传小测验。</p>
</div> </div>

View File

@ -14,6 +14,9 @@
<div ng-repeat="r in resources|filter:{filename:searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"> <div ng-repeat="r in resources|filter:{filename:searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]">
<img src="/images/wechat/courseware.png" width="15" class="ml10 fl" /> <span class="fl ml10 resource-width">{{r.filename}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2">发送</a><div class="cl"></div> <img src="/images/wechat/courseware.png" width="15" class="ml10 fl" /> <span class="fl ml10 resource-width">{{r.filename}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2">发送</a><div class="cl"></div>
<span class="f12 mt5 ml35 c-grey4 fl courseware-from-width hidden">课件来源:{{r.coursename}}</span><span class="f12 ml10 mt5 c-grey4 fl">大小:{{r.attafile_size}}</span><div class="cl"></div> <span class="f12 mt5 ml35 c-grey4 fl courseware-from-width hidden">课件来源:{{r.coursename}}</span><span class="f12 ml10 mt5 c-grey4 fl">大小:{{r.attafile_size}}</span><div class="cl"></div>
</div>
<div ng-if="has_more">
<div id="more" class="more-events mt10" ng-click="loadResourceData(1,page+1);">更多</div>
</div> </div>
<p ng-show="resources && resources.length<=0" class="class-test-tip">暂无课件,<br /> <p ng-show="resources && resources.length<=0" class="class-test-tip">暂无课件,<br />
请登录Trustie网站在PC浏览器中上传课件。</p> 请登录Trustie网站在PC浏览器中上传课件。</p>
@ -21,6 +24,9 @@
<div ng-class="{'undis': currentTab!=2}"> <div ng-class="{'undis': currentTab!=2}">
<div ng-repeat="r in homeworks|filter:{homework_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/homework.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.homework_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2 undis">发送</a><div class="cl"></div> <div ng-repeat="r in homeworks|filter:{homework_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/homework.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.homework_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2 undis">发送</a><div class="cl"></div>
<span class="f12 mt5 ml35 c-grey4 fl other-from-width hidden">作业来源:{{r.coursename}}</span><div class="cl"></div> <span class="f12 mt5 ml35 c-grey4 fl other-from-width hidden">作业来源:{{r.coursename}}</span><div class="cl"></div>
</div>
<div ng-if="homework_has_more">
<div id="more_homeworks" class="more-events mt10" ng-click="loadResourceData(2,homework_page+1);">更多</div>
</div> </div>
<p ng-show="homeworks && homeworks.length<=0" class="class-test-tip">暂无作业,<br /> <p ng-show="homeworks && homeworks.length<=0" class="class-test-tip">暂无作业,<br />
请登录Trustie网站在PC浏览器中创建作业。</p> 请登录Trustie网站在PC浏览器中创建作业。</p>
@ -28,6 +34,9 @@
<div ng-class="{'undis': currentTab!=3}"> <div ng-class="{'undis': currentTab!=3}">
<div ng-repeat="r in exercise|filter:{exercise_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/test.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.exercise_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2 undis">发送</a><div class="cl"></div> <div ng-repeat="r in exercise|filter:{exercise_name: searchText}" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><img src="/images/wechat/test.png" width="15" class="ml10 fl" /><span class="fl ml10 resource-width">{{r.exercise_name}}</span><a ng-click="sendFile(r)" class="fr mr10 link-blue2 undis">发送</a><div class="cl"></div>
<span class="f12 mt5 ml35 c-grey4 other-from-width hidden">题目来源:{{r.coursename}}</span><div class="cl"></div> <span class="f12 mt5 ml35 c-grey4 other-from-width hidden">题目来源:{{r.coursename}}</span><div class="cl"></div>
</div>
<div ng-if="exercise_has_more">
<div id="more_exercises" class="more-events mt10" ng-click="loadResourceData(3,exercise_page+1);">更多</div>
</div> </div>
<p ng-show="exercise && exercise.length<=0" class="class-test-tip">暂无测验,<br /> <p ng-show="exercise && exercise.length<=0" class="class-test-tip">暂无测验,<br />
请登录Trustie网站在PC浏览器中创建测验。</p> 请登录Trustie网站在PC浏览器中创建测验。</p>

View File

@ -2,36 +2,124 @@ app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$l
var vm = $scope; var vm = $scope;
vm.menus = ['课件', '作业', '测验']; vm.menus = ['课件', '作业', '测验'];
vm.resources = null; vm.resources = [];
vm.homeworks = null; vm.homeworks = [];
vm.exercise = null; vm.exercise = [];
vm.has_more = false;
vm.page = 0;
vm.homework_has_more = false;
vm.homework_page = 0;
vm.exercise_has_more = false;
vm.exercise_page = 0;
vm.searchText = ""; vm.searchText = "";
vm.sendFile = function(r){
$location.path("/send_class_list").search({id: r.id});
}
vm.loadResourceData = function (index,page){
if(index == 1){
vm.page = page;
$http({
method: 'POST',
url: apiUrl+ "resources",
data: {token: auth.token(), page: page}
}).then(function successCallback(response) {
if(response.data.page >0) {
vm.resources = vm.resources.concat(response.data.data);
} else {
vm.resources = response.data.data;
}
// rms.save("resources", vm.resources);
vm.has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
// rms.save('homework_has_more', vm.has_more);
// rms.save('homework_page', vm.data.page);
console.log(response.data);
}, function errorCallback(response) {
});
}
else if(index==2 ){
vm.homework_page = page;
$http({
method: 'POST',
url: apiUrl+ "resources/homeworks",
data: {token: auth.token(), page: page}
}).then(function successCallback(response) {
if(response.data.page >0) {
vm.homeworks = vm.homeworks.concat(response.data.data);
} else {
vm.homeworks = response.data.data;
}
// rms.save("homeworks", vm.homeworks);
vm.homework_has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
// rms.save('homework_has_more', vm.has_more);
// rms.save('homework_page', vm.data.page);
console.log(response.data);
}, function errorCallback(response) {
});
}
else if(index==3 ){
vm.exercise_page = page;
$http({
method: 'POST',
url: apiUrl+ "resources/exercises",
data: {token: auth.token(), page: page}
}).then(function successCallback(response) {
if(response.data.page >0) {
vm.exercise = vm.exercise.concat(response.data.data);
} else {
vm.exercise = response.data.data;
}
// rms.save("homeworks", vm.homeworks);
vm.exercise_has_more = (response.data.count + response.data.page * 10) < response.data.all_count;
// rms.save('homework_has_more', vm.has_more);
// rms.save('homework_page', vm.data.page);
console.log(response.data);
}, function errorCallback(response) {
});
}
}
vm.tab = function(index){ vm.tab = function(index){
vm.currentTab = index; vm.currentTab = index;
vm.searchText = ""; vm.searchText = "";
if(index==1 && (!vm.resources || vm.resources.length <= 0 )){
$http.get(config.apiUrl + "resources?token="+auth.token()).then(function(response){ switch(index){
console.log(response.data); //ALL
vm.resources = response.data.data; case 1:
}); if(vm.resources.length<=0){
} else if(index==2 && (!vm.homeworks || vm.homeworks.length <= 0) ){ vm.loadResourceData(index,0);
$http.get(config.apiUrl + "resources/homeworks?token="+auth.token()).then(function(response){ }
console.log(response.data); break;
vm.homeworks = response.data.data; //homework
}); case 2:
} else if(index==3 && (!vm.exercise || vm.exercise.length <= 0) ){ if(vm.homeworks.length<=0){
$http.get(config.apiUrl + "resources/exercies?token="+auth.token()).then(function(response){ vm.loadResourceData(index,0);
console.log(response.data); }
vm.exercise = response.data.data; break;
}); //exercise
case 3:
if(vm.exercise.length<=0){
vm.loadResourceData(index,0);
}
break;
} }
} }
vm.tab(1); vm.tab(1);
vm.sendFile = function(r){
$location.path("/send_class_list").search({id: r.id});
}
}] ); }] );