Description:
tag
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r681:bc0fcfe3abaa - - 22 files changed: 282 inserted, 2 deleted
@@ -0,0 +1,3 | |||
|
1 | + # Place all the behaviors and hooks related to the matching controller here. | |
|
2 | + # All this logic will automatically be available in application.js. | |
|
3 | + # You can use CoffeeScript in this file: http://coffeescript.org/ |
@@ -0,0 +1,3 | |||
|
1 | + // Place all the styles related to the tags controller here. | |
|
2 | + // They will automatically be included in application.css. | |
|
3 | + // You can use Sass (SCSS) here: http://sass-lang.com/ |
@@ -0,0 +1,58 | |||
|
1 | + class TagsController < ApplicationController | |
|
2 | + before_action :set_tag, only: [:show, :edit, :update, :destroy] | |
|
3 | + | |
|
4 | + # GET /tags | |
|
5 | + def index | |
|
6 | + @tags = Tag.all | |
|
7 | + end | |
|
8 | + | |
|
9 | + # GET /tags/1 | |
|
10 | + def show | |
|
11 | + end | |
|
12 | + | |
|
13 | + # GET /tags/new | |
|
14 | + def new | |
|
15 | + @tag = Tag.new | |
|
16 | + end | |
|
17 | + | |
|
18 | + # GET /tags/1/edit | |
|
19 | + def edit | |
|
20 | + end | |
|
21 | + | |
|
22 | + # POST /tags | |
|
23 | + def create | |
|
24 | + @tag = Tag.new(tag_params) | |
|
25 | + | |
|
26 | + if @tag.save | |
|
27 | + redirect_to @tag, notice: 'Tag was successfully created.' | |
|
28 | + else | |
|
29 | + render :new | |
|
30 | + end | |
|
31 | + end | |
|
32 | + | |
|
33 | + # PATCH/PUT /tags/1 | |
|
34 | + def update | |
|
35 | + if @tag.update(tag_params) | |
|
36 | + redirect_to @tag, notice: 'Tag was successfully updated.' | |
|
37 | + else | |
|
38 | + render :edit | |
|
39 | + end | |
|
40 | + end | |
|
41 | + | |
|
42 | + # DELETE /tags/1 | |
|
43 | + def destroy | |
|
44 | + @tag.destroy | |
|
45 | + redirect_to tags_url, notice: 'Tag was successfully destroyed.' | |
|
46 | + end | |
|
47 | + | |
|
48 | + private | |
|
49 | + # Use callbacks to share common setup or constraints between actions. | |
|
50 | + def set_tag | |
|
51 | + @tag = Tag.find(params[:id]) | |
|
52 | + end | |
|
53 | + | |
|
54 | + # Only allow a trusted parameter "white list" through. | |
|
55 | + def tag_params | |
|
56 | + params.require(:tag).permit(:name, :description, :public) | |
|
57 | + end | |
|
58 | + end |
@@ -0,0 +1,8 | |||
|
1 | + class ProblemTag < ActiveRecord::Base | |
|
2 | + self.table_name = 'problems_tags' | |
|
3 | + | |
|
4 | + belongs_to :problem | |
|
5 | + belongs_to :tag | |
|
6 | + | |
|
7 | + validates_uniqueness_of :problem_id, scope: :tag_id, message: ->(object, data) { "'#{Problem.find(data[:value]).full_name}' is already has this tag" } | |
|
8 | + end |
@@ -0,0 +1,4 | |||
|
1 | + class Tag < ActiveRecord::Base | |
|
2 | + has_many :problems_tags, class_name: ProblemTag | |
|
3 | + has_many :problems, through: :problems_tags | |
|
4 | + end |
@@ -0,0 +1,22 | |||
|
1 | + = form_for @tag do |f| | |
|
2 | + - if @tag.errors.any? | |
|
3 | + #error_explanation | |
|
4 | + %h2= "#{pluralize(@tag.errors.count, "error")} prohibited this tag from being saved:" | |
|
5 | + %ul | |
|
6 | + - @tag.errors.full_messages.each do |msg| | |
|
7 | + %li= msg | |
|
8 | + | |
|
9 | + .row | |
|
10 | + .col-md-6 | |
|
11 | + .form-group.field | |
|
12 | + = f.label :name | |
|
13 | + = f.text_field :name, class: 'form-control' | |
|
14 | + .form-group.field | |
|
15 | + = f.label :description | |
|
16 | + = f.text_area :description, class: 'form-control' | |
|
17 | + .form-group.field | |
|
18 | + = f.label :public | |
|
19 | + = f.text_field :public, class: 'form-control' | |
|
20 | + .actions | |
|
21 | + = f.submit 'Save', class: 'btn btn-primary' | |
|
22 | + .col-md-6 |
@@ -0,0 +1,7 | |||
|
1 | + %h1 Editing tag | |
|
2 | + | |
|
3 | + = render 'form' | |
|
4 | + | |
|
5 | + = link_to 'Show', @tag | |
|
6 | + \| | |
|
7 | + = link_to 'Back', tags_path |
@@ -0,0 +1,26 | |||
|
1 | + %h1 Tags | |
|
2 | + | |
|
3 | + = link_to 'New Tag', new_tag_path, class: 'btn btn-success' | |
|
4 | + | |
|
5 | + %table.table.table-hover | |
|
6 | + %thead | |
|
7 | + %tr | |
|
8 | + %th Name | |
|
9 | + %th Description | |
|
10 | + %th Public | |
|
11 | + %th | |
|
12 | + %th | |
|
13 | + %th | |
|
14 | + | |
|
15 | + %tbody | |
|
16 | + - @tags.each do |tag| | |
|
17 | + %tr | |
|
18 | + %td= tag.name | |
|
19 | + %td= tag.description | |
|
20 | + %td= tag.public | |
|
21 | + %td= link_to 'Show', tag | |
|
22 | + %td= link_to 'Edit', edit_tag_path(tag) | |
|
23 | + %td= link_to 'Destroy', tag, :method => :delete, :data => { :confirm => 'Are you sure?' } | |
|
24 | + | |
|
25 | + %br | |
|
26 | + |
@@ -0,0 +1,15 | |||
|
1 | + %p#notice= notice | |
|
2 | + | |
|
3 | + %p | |
|
4 | + %b Name: | |
|
5 | + = @tag.name | |
|
6 | + %p | |
|
7 | + %b Description: | |
|
8 | + = @tag.description | |
|
9 | + %p | |
|
10 | + %b Public: | |
|
11 | + = @tag.public | |
|
12 | + | |
|
13 | + = link_to 'Edit', edit_tag_path(@tag) | |
|
14 | + \| | |
|
15 | + = link_to 'Back', tags_path |
@@ -0,0 +1,11 | |||
|
1 | + class CreateTags < ActiveRecord::Migration | |
|
2 | + def change | |
|
3 | + create_table :tags do |t| | |
|
4 | + t.string :name, null: false | |
|
5 | + t.text :description | |
|
6 | + t.boolean :public | |
|
7 | + | |
|
8 | + t.timestamps null: false | |
|
9 | + end | |
|
10 | + end | |
|
11 | + end |
@@ -0,0 +1,10 | |||
|
1 | + class CreateProblemTags < ActiveRecord::Migration | |
|
2 | + def change | |
|
3 | + create_table :problems_tags do |t| | |
|
4 | + t.references :problem, index: true, foreign_key: true | |
|
5 | + t.references :tag, index: true, foreign_key: true | |
|
6 | + | |
|
7 | + t.index [:problem_id,:tag_id], unique: true | |
|
8 | + end | |
|
9 | + end | |
|
10 | + end |
@@ -0,0 +1,49 | |||
|
1 | + require 'test_helper' | |
|
2 | + | |
|
3 | + class TagsControllerTest < ActionController::TestCase | |
|
4 | + setup do | |
|
5 | + @tag = tags(:one) | |
|
6 | + end | |
|
7 | + | |
|
8 | + test "should get index" do | |
|
9 | + get :index | |
|
10 | + assert_response :success | |
|
11 | + assert_not_nil assigns(:tags) | |
|
12 | + end | |
|
13 | + | |
|
14 | + test "should get new" do | |
|
15 | + get :new | |
|
16 | + assert_response :success | |
|
17 | + end | |
|
18 | + | |
|
19 | + test "should create tag" do | |
|
20 | + assert_difference('Tag.count') do | |
|
21 | + post :create, tag: { description: @tag.description, name: @tag.name, public: @tag.public } | |
|
22 | + end | |
|
23 | + | |
|
24 | + assert_redirected_to tag_path(assigns(:tag)) | |
|
25 | + end | |
|
26 | + | |
|
27 | + test "should show tag" do | |
|
28 | + get :show, id: @tag | |
|
29 | + assert_response :success | |
|
30 | + end | |
|
31 | + | |
|
32 | + test "should get edit" do | |
|
33 | + get :edit, id: @tag | |
|
34 | + assert_response :success | |
|
35 | + end | |
|
36 | + | |
|
37 | + test "should update tag" do | |
|
38 | + patch :update, id: @tag, tag: { description: @tag.description, name: @tag.name, public: @tag.public } | |
|
39 | + assert_redirected_to tag_path(assigns(:tag)) | |
|
40 | + end | |
|
41 | + | |
|
42 | + test "should destroy tag" do | |
|
43 | + assert_difference('Tag.count', -1) do | |
|
44 | + delete :destroy, id: @tag | |
|
45 | + end | |
|
46 | + | |
|
47 | + assert_redirected_to tags_path | |
|
48 | + end | |
|
49 | + end |
@@ -0,0 +1,9 | |||
|
1 | + # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |
|
2 | + | |
|
3 | + one: | |
|
4 | + problem_id: | |
|
5 | + tag_id: | |
|
6 | + | |
|
7 | + two: | |
|
8 | + problem_id: | |
|
9 | + tag_id: |
@@ -0,0 +1,11 | |||
|
1 | + # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |
|
2 | + | |
|
3 | + one: | |
|
4 | + name: MyString | |
|
5 | + description: MyString | |
|
6 | + public: | |
|
7 | + | |
|
8 | + two: | |
|
9 | + name: MyString | |
|
10 | + description: MyString | |
|
11 | + public: |
@@ -0,0 +1,7 | |||
|
1 | + require 'test_helper' | |
|
2 | + | |
|
3 | + class ProblemTagTest < ActiveSupport::TestCase | |
|
4 | + # test "the truth" do | |
|
5 | + # assert true | |
|
6 | + # end | |
|
7 | + end |
@@ -0,0 +1,7 | |||
|
1 | + require 'test_helper' | |
|
2 | + | |
|
3 | + class TagTest < ActiveSupport::TestCase | |
|
4 | + # test "the truth" do | |
|
5 | + # assert true | |
|
6 | + # end | |
|
7 | + end |
@@ -1,21 +1,24 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | has_and_belongs_to_many :contests, :uniq => true |
|
5 | 5 | |
|
6 | 6 | #has_and_belongs_to_many :groups |
|
7 | 7 | has_many :groups_problems, class_name: GroupProblem |
|
8 | 8 | has_many :groups, :through => :groups_problems |
|
9 | 9 | |
|
10 | + has_many :problems_tags, class_name: ProblemTag | |
|
11 | + has_many :tags, through: :problems_tags | |
|
12 | + | |
|
10 | 13 | has_many :test_pairs, :dependent => :delete_all |
|
11 | 14 | has_many :testcases, :dependent => :destroy |
|
12 | 15 | |
|
13 | 16 | validates_presence_of :name |
|
14 | 17 | validates_format_of :name, :with => /\A\w+\z/ |
|
15 | 18 | validates_presence_of :full_name |
|
16 | 19 | |
|
17 | 20 | scope :available, -> { where(available: true) } |
|
18 | 21 | |
|
19 | 22 | DEFAULT_TIME_LIMIT = 1 |
|
20 | 23 | DEFAULT_MEMORY_LIMIT = 32 |
|
21 | 24 |
@@ -9,15 +9,15 | |||
|
9 | 9 | Rails.application.config.assets.paths << Rails.root.join('node_modules') |
|
10 | 10 | Rails.application.config.assets.paths << Rails.root.join('vendor/assets/fonts') |
|
11 | 11 | |
|
12 | 12 | # Precompile additional assets. |
|
13 | 13 | # application.js, application.css, and all non-JS/CSS in the app/assets |
|
14 | 14 | # folder are already added. |
|
15 | 15 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) |
|
16 | 16 | |
|
17 | 17 | Rails.application.config.assets.precompile += ['announcement_refresh.js','effects.js','site_update.js'] |
|
18 | 18 | Rails.application.config.assets.precompile += ['local_jquery.js','tablesorter-theme.cafe.css'] |
|
19 | 19 | %w( announcements submissions configurations contests contest_management graders heartbeat |
|
20 | 20 | login main messages problems report site sites sources tasks groups |
|
21 | - test user_admin users ).each do |controller| | |
|
21 | + test user_admin users tags).each do |controller| | |
|
22 | 22 | Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}.css"] |
|
23 | 23 | end |
@@ -1,13 +1,14 | |||
|
1 | 1 | CafeGrader::Application.routes.draw do |
|
2 | + resources :tags | |
|
2 | 3 | get "sources/direct_edit" |
|
3 | 4 | |
|
4 | 5 | root :to => 'main#login' |
|
5 | 6 | |
|
6 | 7 | #logins |
|
7 | 8 | get 'login/login', to: 'login#login' |
|
8 | 9 | |
|
9 | 10 | resources :contests |
|
10 | 11 | |
|
11 | 12 | resources :sites |
|
12 | 13 | |
|
13 | 14 | resources :announcements do |
@@ -2,25 +2,25 | |||
|
2 | 2 | # This file is auto-generated from the current state of the database. Instead |
|
3 | 3 | # of editing this file, please use the migrations feature of Active Record to |
|
4 | 4 | # incrementally modify your database, and then regenerate this schema definition. |
|
5 | 5 | # |
|
6 | 6 | # Note that this schema.rb definition is the authoritative source for your |
|
7 | 7 | # database schema. If you need to create the application database on another |
|
8 | 8 | # system, you should be using db:schema:load, not running all the migrations |
|
9 | 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
10 | 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
11 | 11 | # |
|
12 | 12 | # It's strongly recommended that you check this file into your version control system. |
|
13 | 13 | |
|
14 |
- ActiveRecord::Schema.define(version: 2017091 |
|
|
14 | + ActiveRecord::Schema.define(version: 20170914150742) do | |
|
15 | 15 | |
|
16 | 16 | create_table "announcements", force: :cascade do |t| |
|
17 | 17 | t.string "author", limit: 255 |
|
18 | 18 | t.text "body", limit: 65535 |
|
19 | 19 | t.boolean "published" |
|
20 | 20 | t.datetime "created_at", null: false |
|
21 | 21 | t.datetime "updated_at", null: false |
|
22 | 22 | t.boolean "frontpage", default: false |
|
23 | 23 | t.boolean "contest_only", default: false |
|
24 | 24 | t.string "title", limit: 255 |
|
25 | 25 | t.string "notes", limit: 255 |
|
26 | 26 | end |
@@ -137,24 +137,33 | |||
|
137 | 137 | t.string "full_name", limit: 255 |
|
138 | 138 | t.integer "full_score", limit: 4 |
|
139 | 139 | t.date "date_added" |
|
140 | 140 | t.boolean "available" |
|
141 | 141 | t.string "url", limit: 255 |
|
142 | 142 | t.integer "description_id", limit: 4 |
|
143 | 143 | t.boolean "test_allowed" |
|
144 | 144 | t.boolean "output_only" |
|
145 | 145 | t.string "description_filename", limit: 255 |
|
146 | 146 | t.boolean "view_testcase" |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | + create_table "problems_tags", force: :cascade do |t| | |
|
150 | + t.integer "problem_id", limit: 4 | |
|
151 | + t.integer "tag_id", limit: 4 | |
|
152 | + end | |
|
153 | + | |
|
154 | + add_index "problems_tags", ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true, using: :btree | |
|
155 | + add_index "problems_tags", ["problem_id"], name: "index_problems_tags_on_problem_id", using: :btree | |
|
156 | + add_index "problems_tags", ["tag_id"], name: "index_problems_tags_on_tag_id", using: :btree | |
|
157 | + | |
|
149 | 158 | create_table "rights", force: :cascade do |t| |
|
150 | 159 | t.string "name", limit: 255 |
|
151 | 160 | t.string "controller", limit: 255 |
|
152 | 161 | t.string "action", limit: 255 |
|
153 | 162 | end |
|
154 | 163 | |
|
155 | 164 | create_table "rights_roles", id: false, force: :cascade do |t| |
|
156 | 165 | t.integer "right_id", limit: 4 |
|
157 | 166 | t.integer "role_id", limit: 4 |
|
158 | 167 | end |
|
159 | 168 | |
|
160 | 169 | add_index "rights_roles", ["role_id"], name: "index_rights_roles_on_role_id", using: :btree |
@@ -210,24 +219,32 | |||
|
210 | 219 | t.text "grader_comment", limit: 65535 |
|
211 | 220 | t.integer "number", limit: 4 |
|
212 | 221 | t.string "source_filename", limit: 255 |
|
213 | 222 | t.float "max_runtime", limit: 24 |
|
214 | 223 | t.integer "peak_memory", limit: 4 |
|
215 | 224 | t.integer "effective_code_length", limit: 4 |
|
216 | 225 | t.string "ip_address", limit: 255 |
|
217 | 226 | end |
|
218 | 227 | |
|
219 | 228 | add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree |
|
220 | 229 | add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree |
|
221 | 230 | |
|
231 | + create_table "tags", force: :cascade do |t| | |
|
232 | + t.string "name", limit: 255, null: false | |
|
233 | + t.text "description", limit: 65535 | |
|
234 | + t.boolean "public" | |
|
235 | + t.datetime "created_at", null: false | |
|
236 | + t.datetime "updated_at", null: false | |
|
237 | + end | |
|
238 | + | |
|
222 | 239 | create_table "tasks", force: :cascade do |t| |
|
223 | 240 | t.integer "submission_id", limit: 4 |
|
224 | 241 | t.datetime "created_at" |
|
225 | 242 | t.integer "status", limit: 4 |
|
226 | 243 | t.datetime "updated_at" |
|
227 | 244 | end |
|
228 | 245 | |
|
229 | 246 | add_index "tasks", ["submission_id"], name: "index_tasks_on_submission_id", using: :btree |
|
230 | 247 | |
|
231 | 248 | create_table "test_pairs", force: :cascade do |t| |
|
232 | 249 | t.integer "problem_id", limit: 4 |
|
233 | 250 | t.text "input", limit: 16777215 |
@@ -290,13 +307,15 | |||
|
290 | 307 | t.integer "country_id", limit: 4 |
|
291 | 308 | t.boolean "activated", default: false |
|
292 | 309 | t.datetime "created_at" |
|
293 | 310 | t.datetime "updated_at" |
|
294 | 311 | t.boolean "enabled", default: true |
|
295 | 312 | t.string "remark", limit: 255 |
|
296 | 313 | t.string "last_ip", limit: 255 |
|
297 | 314 | t.string "section", limit: 255 |
|
298 | 315 | end |
|
299 | 316 | |
|
300 | 317 | add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree |
|
301 | 318 | |
|
319 | + add_foreign_key "problems_tags", "problems" | |
|
320 | + add_foreign_key "problems_tags", "tags" | |
|
302 | 321 | end |
You need to be logged in to leave comments.
Login now