加入我的资源

This commit is contained in:
guange 2016-06-27 17:24:06 +08:00
parent f6f329b00f
commit 1e6454efc0
13 changed files with 146 additions and 21 deletions

View File

@ -18,6 +18,7 @@ module Mobile
require_relative 'apis/blog_comments' require_relative 'apis/blog_comments'
require_relative 'apis/new_comment' require_relative 'apis/new_comment'
require_relative 'apis/praise' require_relative 'apis/praise'
require_relative 'apis/resources'
class API < Grape::API class API < Grape::API
version 'v1', using: :path version 'v1', using: :path
@ -71,6 +72,7 @@ module Mobile
mount Apis::BlogComments mount Apis::BlogComments
mount Apis::NewComment mount Apis::NewComment
mount Apis::Praise mount Apis::Praise
mount Apis::Resources
add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development? add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?

View File

@ -0,0 +1,55 @@
#coding=utf-8
module Mobile
module Apis
class Resources < Grape::API
resource :resources do
desc '获取所有课件'
params do
requires :token, type: String
end
get do
authenticate!
data = current_user.course_attachments
present :data, data, with: Mobile::Entities::Attachment
present :status, 0
end
desc '获取所有作业'
params do
requires :token, type: String
end
get 'homeworks' do
authenticate!
homeworks = current_user.homework_commons
present :data, homeworks, with: Mobile::Entities::Homework
present :status, 0
end
desc '获取所有测验'
params do
requires :token, type: String
end
get 'exercies' do
authenticate!
exercises = current_user.exercises
present :data, exercises, with: Mobile::Entities::Exercise
present :status, 0
end
end
end
end
end

View File

@ -145,6 +145,7 @@ class User < Principal
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :principal_acts, :class_name => 'PrincipalActivity',:as =>:principal_act ,:dependent => :destroy has_many :principal_acts, :class_name => 'PrincipalActivity',:as =>:principal_act ,:dependent => :destroy
has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'" has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'"
has_many :course_attachments , :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Course'"
#### ####
# added by bai # added by bai
has_many :join_in_contests, :dependent => :destroy has_many :join_in_contests, :dependent => :destroy

View File

@ -40,7 +40,7 @@
<script src="/javascripts/wechat/controllers/invite_code.js"></script> <script src="/javascripts/wechat/controllers/invite_code.js"></script>
<script src="/javascripts/wechat/controllers/login.js"></script> <script src="/javascripts/wechat/controllers/login.js"></script>
<script src="/javascripts/wechat/controllers/activity.js"></script> <script src="/javascripts/wechat/controllers/activity.js"></script>
<script src="/javascripts/wechat/controllers/add_class.js"></script> <script src="/javascripts/wechat/controllers/new_class.js"></script>
<script src="/javascripts/wechat/controllers/blog.js"></script> <script src="/javascripts/wechat/controllers/blog.js"></script>
<script src="/javascripts/wechat/controllers/course_notice.js"></script> <script src="/javascripts/wechat/controllers/course_notice.js"></script>
<script src="/javascripts/wechat/controllers/discussion.js"></script> <script src="/javascripts/wechat/controllers/discussion.js"></script>
@ -49,6 +49,7 @@
<script src="/javascripts/wechat/controllers/journals.js"></script> <script src="/javascripts/wechat/controllers/journals.js"></script>
<script src="/javascripts/wechat/controllers/myclass.js"></script> <script src="/javascripts/wechat/controllers/myclass.js"></script>
<script src="/javascripts/wechat/controllers/class_list.js"></script> <script src="/javascripts/wechat/controllers/class_list.js"></script>
<script src="/javascripts/wechat/controllers/myresource.js"></script>
<script src="/javascripts/wechat/others/routes.js"></script> <script src="/javascripts/wechat/others/routes.js"></script>
</body> </body>

View File

@ -1,13 +0,0 @@
<div class="post-container">
<div class="add-class-box">
<p class="tac add-class-tip">输入班级邀请码,即刻加入班级!</p>
<form class="mb20">
<input type="text" class="class-number-input" />
</form>
<a href="javascript:void(0);" class="c-grey4 fl cancel-btn">取消</a>
<div class="slice fl">
<div class="slice-line"></div>
</div>
<a href="javascript:void(0);" class="c-blue fl submit-btn">确定</a>
</div>
</div>

View File

@ -13,9 +13,9 @@
<div class="bottom-tab-wrap mt10"> <div class="bottom-tab-wrap mt10">
<a href="javascript:void(0);" class="weixin-tab link-blue2 border-top">新建课程</a> <a ng-click="newClass()" href="javascript:void(0);" class="weixin-tab link-blue2 border-top">新建课程</a>
<a href="javascript:void(0);" class="weixin-tab link-blue2 border-top">加入班级</a> <a href="javascript:void(0);" class="weixin-tab link-blue2 border-top">加入班级</a>
<a href="javascript:void(0);" class="weixin-tab link-blue2 border-top">我的资源</a> <a ng-click="goResource()" href="javascript:void(0);" class="weixin-tab link-blue2 border-top">我的资源</a>
</div> </div>
</div> </div>

View File

@ -0,0 +1,26 @@
<div class="post-container">
<div class="class-detail-name">我的资源</div>
<div class="tab-wrap">
<a ng-click="tab($index+1)" ng-repeat="menu in menus" id="class_tab_1" href="javascript:void(0);" ng-class="['weixin-tab', {'class-tab-active': currentTab == $index+1}]">{{menu}}</a>
</div>
<div class="class-search-wrap">
<div class="class-search-inner"> <img src="/images/wechat/search.png" width="18" class="class-search-icon" />
<input class="class-detail-search" placeholder="输入关键词进行搜索" />
</div>
</div>
<div ng-class="{'undis': currentTab!=1}">
<div ng-repeat="r in resources" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><span class="fl ml10">{{r.filename}}</span><a herf="javascript:void(0);" class="fr mr10 link-blue2">发送</a></div>
<p ng-show="resources.length<=0" class="class-test-tip">暂无课件,<br />
请登录Trustie网站,在PC浏览器中上传课件。</p>
</div>
<div ng-class="{'undis': currentTab!=2}">
<div ng-repeat="r in homeworks" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><span class="fl ml10">{{r.homework_name}}</span><a herf="javascript:void(0);" class="fr mr10 link-blue2">发送</a></div>
<p ng-show="homeworks.length<=0" class="class-test-tip">暂无作业,<br />
请登录Trustie网站,在PC浏览器中创建作业。</p>
</div>
<div ng-class="{'undis': currentTab!=3}">
<div ng-repeat="r in exercise" ng-class="['class-detail-row', 'f13', 'c-grey3', {'border-top': $first}]"><span class="fl ml10">{{r.exercise_name}}</span><a herf="javascript:void(0);" class="fr mr10 link-blue2">发送</a></div>
<p ng-show="exercise.length<=0" class="class-test-tip">暂无测验,<br />
请登录Trustie网站,在PC浏览器中创建测验。</p>
</div>
</div>

View File

@ -0,0 +1,7 @@
<div class="post-container">
<div class="blue-title">新建课程</div>
<div class="course-list-row f13 c-grey3 mt30"><span class="fl ml15 c-grey3">课程</span><input class="new-class-input ml25" placeholder="请输入课程名" /></div>
<div class="course-list-row f13 c-grey3 mt10"><span class="fl ml15 c-grey3">班级</span><input class="new-class-input ml25" placeholder="请输入班级名" /></div>
<div class="tac"><a herf="javascript:void(0);" class="link-blue2 f13 mt15 inline-block add-class-link">+新增班级</a></div>
<a href="javascript:void(0);" class="finish-btn">完成</a>
</div>

View File

@ -1,4 +0,0 @@
app.controller('AddClassController', ['$scope',function($scope){
}]);

View File

@ -19,5 +19,12 @@ app.controller('ClassListController', ['$scope','config','auth','$http','$locati
$location.path("/myclass").search({id: course_id}); $location.path("/myclass").search({id: course_id});
} }
vm.newClass = function(){
$location.path("/new_class");
}
vm.goResource =function(){
$location.path("/myresource");
}
}]); }]);

View File

@ -0,0 +1,30 @@
app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', function($scope, $http, auth, config){
var vm = $scope;
vm.menus = ['课件', '作业', '测验'];
vm.resources = [];
vm.homeworks = [];
vm.exercise = [];
vm.tab = function(index){
vm.currentTab = index;
if(index==1){
$http.get(config.apiUrl + "resources?token="+auth.token()).then(function(response){
console.log(response.data);
vm.resources = response.data.data;
});
} else if(index==2){
$http.get(config.apiUrl + "resources/homeworks?token="+auth.token()).then(function(response){
console.log(response.data);
vm.homeworks = response.data.data;
});
} else if(index==3){
$http.get(config.apiUrl + "resources/exercies?token="+auth.token()).then(function(response){
console.log(response.data);
vm.exercise = response.data.data;
});
}
}
vm.tab(1);
}] );

View File

@ -0,0 +1,12 @@
app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', function($scope, $http, auth, config){
var vm = $scope;
vm.resources = [];
vm.homeworks = [];
vm.exercises = [];
}] );

View File

@ -30,9 +30,10 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func
.when('/course_discussion/:id', makeRoute('course_discussion.html', 'DiscussionController')) .when('/course_discussion/:id', makeRoute('course_discussion.html', 'DiscussionController'))
.when('/journal_for_message/:id', makeRoute('jour_message_detail.html', 'JournalsController')) .when('/journal_for_message/:id', makeRoute('jour_message_detail.html', 'JournalsController'))
.when('/blog_comment/:id', makeRoute('blog_detail.html', 'BlogController')) .when('/blog_comment/:id', makeRoute('blog_detail.html', 'BlogController'))
.when('/add_class', makeRoute('add_class.html', 'AddClassController'))
.when('/myclass', makeRoute('myclass.html', 'MyClassController')) .when('/myclass', makeRoute('myclass.html', 'MyClassController'))
.when('/new_class', makeRoute('new_class.html', 'NewClassController'))
.when('/class_list', makeRoute('class_list.html', 'ClassListController')) .when('/class_list', makeRoute('class_list.html', 'ClassListController'))
.when('/myresource', makeRoute('myresource.html', 'MyResourceController'))
.when('/invite_code', makeRoute('invite_code.html', 'InviteCodeController')) .when('/invite_code', makeRoute('invite_code.html', 'InviteCodeController'))
.otherwise({ .otherwise({
redirectTo: '/activites' redirectTo: '/activites'