diff --git a/app/assets/javascripts/subject.js.coffee b/app/assets/javascripts/subject.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/subject.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/subject.css.scss b/app/assets/stylesheets/subject.css.scss new file mode 100644 index 000000000..62eade901 --- /dev/null +++ b/app/assets/stylesheets/subject.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the subject controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/subject_controller.rb b/app/controllers/subject_controller.rb new file mode 100644 index 000000000..0413d7fa9 --- /dev/null +++ b/app/controllers/subject_controller.rb @@ -0,0 +1,16 @@ +class SubjectController < ApplicationController + + def index + @order = "created_at" + @sort = "desc" + search = params[:search] + @subjects = Subject.where("name like ?", "%#{search}%").reorder("created_at desc") + @subjects_count = @subjects.count + @limit = 16 + @is_remote = true + @subject_pages = Paginator.new @subjects_count, @limit, params['page'] || 1 + @offset ||= @subject_pages.offset + @subjects = paginateHelper @subjects, @limit + render :layout => "base_edu" + end +end diff --git a/app/helpers/subject_helper.rb b/app/helpers/subject_helper.rb new file mode 100644 index 000000000..ea8952691 --- /dev/null +++ b/app/helpers/subject_helper.rb @@ -0,0 +1,2 @@ +module SubjectHelper +end diff --git a/app/models/subject.rb b/app/models/subject.rb new file mode 100644 index 000000000..b4ecca5d5 --- /dev/null +++ b/app/models/subject.rb @@ -0,0 +1,5 @@ +class Subject < ActiveRecord::Base + belongs_to :user + belongs_to :course_list + attr_accessible :description, :name, :status, :visits, :user_id, :course_list_id +end diff --git a/app/models/user.rb b/app/models/user.rb index 676e57835..ad53fd971 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -131,6 +131,8 @@ class User < Principal has_many :shixun_members, :dependent => :destroy has_many :challenges, :dependent => :destroy + has_many :subjects + has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} has_many :changesets, :dependent => :nullify diff --git a/app/views/subject/index.html.erb b/app/views/subject/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/db/migrate/20170711091159_create_subjects.rb b/db/migrate/20170711091159_create_subjects.rb new file mode 100644 index 000000000..b8a383ae2 --- /dev/null +++ b/db/migrate/20170711091159_create_subjects.rb @@ -0,0 +1,16 @@ +class CreateSubjects < ActiveRecord::Migration + def change + create_table :subjects do |t| + t.string :name + t.text :description + t.references :user + t.references :course_list + t.integer :visits + t.integer :status + + t.timestamps + end + add_index :subjects, :user_id + add_index :subjects, :course_list_id + end +end diff --git a/spec/controllers/subject_controller_spec.rb b/spec/controllers/subject_controller_spec.rb new file mode 100644 index 000000000..389d7d550 --- /dev/null +++ b/spec/controllers/subject_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SubjectController, :type => :controller do + +end diff --git a/spec/factories/subjects.rb b/spec/factories/subjects.rb new file mode 100644 index 000000000..1982df2ae --- /dev/null +++ b/spec/factories/subjects.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :subject do + name "MyString" +description "MyText" +user nil +course_list nil +visits 1 +status 1 + end + +end diff --git a/spec/models/subject_spec.rb b/spec/models/subject_spec.rb new file mode 100644 index 000000000..b642d0cc7 --- /dev/null +++ b/spec/models/subject_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Subject, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end