Added link feature init version.
This commit is contained in:
parent
48c92b8a71
commit
6e0bc3edbc
9 changed files with 259 additions and 45 deletions
|
@ -207,6 +207,13 @@ class Index extends App.Controller
|
|||
ticket: @ticket,
|
||||
)
|
||||
|
||||
# start link info controller
|
||||
new App.LinkInfo(
|
||||
el: @el.find('#link_info'),
|
||||
object_type: 'Ticket',
|
||||
object: @ticket,
|
||||
)
|
||||
|
||||
# scrall to article if given
|
||||
if @article_id
|
||||
offset = document.getElementById( 'article-' + @article_id ).offsetTop
|
||||
|
|
62
app/assets/javascripts/app/controllers/link_info.js.coffee
Normal file
62
app/assets/javascripts/app/controllers/link_info.js.coffee
Normal file
|
@ -0,0 +1,62 @@
|
|||
$ = jQuery.sub()
|
||||
|
||||
class App.LinkInfo extends App.Controller
|
||||
events:
|
||||
'focusout [data-type=edit]': 'update',
|
||||
|
||||
constructor: ->
|
||||
super
|
||||
|
||||
# fetch item on demand
|
||||
# get data
|
||||
App.Com.ajax(
|
||||
id: 'links_' + @object_id + '_' + @object,
|
||||
type: 'GET',
|
||||
url: '/links',
|
||||
data: {
|
||||
link_object: @object_type,
|
||||
link_object_value: @object.id,
|
||||
}
|
||||
processData: true,
|
||||
success: (data, status, xhr) =>
|
||||
@links = data.links
|
||||
|
||||
# load user collection
|
||||
@loadCollection( type: 'User', data: data.users )
|
||||
|
||||
# load ticket collection
|
||||
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||
|
||||
@render()
|
||||
)
|
||||
|
||||
render: () ->
|
||||
|
||||
list = {}
|
||||
for item in @links
|
||||
if !list[ item['link_type'] ]
|
||||
list[ item['link_type'] ] = []
|
||||
|
||||
if item['link_object'] is 'Ticket'
|
||||
list[ item['link_type'] ].push App.Ticket.find( item['link_object_value'] )
|
||||
|
||||
return if _.isEmpty( @links )
|
||||
|
||||
# insert data
|
||||
@html App.view('link_info')(
|
||||
links: list,
|
||||
)
|
||||
|
||||
# @ticketPopups(
|
||||
# selector: '.user-tickets',
|
||||
# user_id: user_id,
|
||||
# )
|
||||
|
||||
update: (e) =>
|
||||
|
||||
# update changes
|
||||
note = $(e.target).parent().find('[data-type=edit]').val()
|
||||
user = App.User.find(@user_id)
|
||||
if user.note isnt note
|
||||
user.updateAttributes( note: note )
|
||||
@log 'update', e, note, user
|
|
@ -106,17 +106,9 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
<div class="row">
|
||||
<div class="well">
|
||||
<h3>Linked Objects</h3>
|
||||
<ul>
|
||||
<li><a href="#" data-type="history">T:12312313</a></li>
|
||||
<li><a href="#" data-type="history">F:12313123</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
<div class="row" id="link_info"></div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
13
app/assets/javascripts/app/views/link_info.jst.eco
Normal file
13
app/assets/javascripts/app/views/link_info.jst.eco
Normal file
|
@ -0,0 +1,13 @@
|
|||
<div class="well">
|
||||
<h3><%- T('Linked Objects') %></h3>
|
||||
|
||||
<% for type of @links: %>
|
||||
<strong><%- T( type ) %></strong>
|
||||
<ul>
|
||||
<% for item in @links[type]: %>
|
||||
<li><a href="#ticket/zoom/<%= item.id %>" data-type="" title="<%= item.title %>">T:<%= item.number %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
</div>
|
69
app/controllers/links_controller.rb
Normal file
69
app/controllers/links_controller.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
class LinksController < ApplicationController
|
||||
before_filter :authentication_check
|
||||
|
||||
# GET /links
|
||||
def index
|
||||
links = Link.list(
|
||||
:link_object => params[:link_object],
|
||||
:link_object_value => params[:link_object_value],
|
||||
)
|
||||
|
||||
#
|
||||
tickets = []
|
||||
users = {}
|
||||
link_list = []
|
||||
links.each { |item|
|
||||
link_list.push item
|
||||
if item['link_object'] == 'Ticket'
|
||||
data = Ticket.full_data( item['link_object_value'] )
|
||||
tickets.push data
|
||||
if !users[ data['owner_id'] ]
|
||||
users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] )
|
||||
end
|
||||
if !users[ data['customer_id'] ]
|
||||
users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] )
|
||||
end
|
||||
if !users[ data['created_by_id'] ]
|
||||
users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] )
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
# return result
|
||||
render :json => {
|
||||
:links => link_list,
|
||||
:tickets => tickets,
|
||||
:users => users,
|
||||
}
|
||||
end
|
||||
|
||||
# POST /links/add
|
||||
def add
|
||||
# @template.created_by_id = current_user.id
|
||||
link = Link.add(
|
||||
:link_type => params[:link_type],
|
||||
:link_object_source => params[:link_object_source],
|
||||
:link_object_source_value => params[:link_object_source_value],
|
||||
:link_object_target => params[:link_object_target],
|
||||
:link_object_target_value => params[:link_object_target_value]
|
||||
)
|
||||
|
||||
if link
|
||||
render :json => link, :status => :created
|
||||
else
|
||||
render :json => link.errors, :status => :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /links/delete
|
||||
def delete
|
||||
@template = Template.find(params[:id])
|
||||
|
||||
if @template.update_attributes(params[:template])
|
||||
render :json => @template, :status => :ok
|
||||
else
|
||||
render :json => @template.errors, :status => :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,27 +1,33 @@
|
|||
class Link < ActiveRecord::Base
|
||||
has_many :link_types
|
||||
belongs_to :link_type, :class_name => 'Link::Type'
|
||||
belongs_to :link_object, :class_name => 'Link::Object'
|
||||
|
||||
#before_create :check_object
|
||||
#after_create :after_create, :cache_delete
|
||||
#after_update :cache_delete
|
||||
#after_destroy :cache_delete
|
||||
#before_create :check_object
|
||||
#after_create :after_create, :cache_delete
|
||||
#after_update :cache_delete
|
||||
#after_destroy :cache_delete
|
||||
|
||||
=begin
|
||||
|
||||
Link.add(
|
||||
:link_types_id => 12,
|
||||
:link_type => 'normal',
|
||||
:link_object_source => 'Ticket',
|
||||
:link_object_source_value => 1,
|
||||
:link_object_source_value => 6,
|
||||
:link_object_target => 'Ticket',
|
||||
:link_object_target_value => 1
|
||||
:link_object_target_value => 31
|
||||
)
|
||||
|
||||
Link.add(
|
||||
:link_types_id => 12,
|
||||
:link_object_source_id => '1',
|
||||
:link_object_source_id => 1,
|
||||
:link_object_source_value => 1,
|
||||
:link_object_target_id => '1',
|
||||
:link_object_target_value => 1,
|
||||
:link_object_target_id => 1,
|
||||
:link_object_target_value => 1
|
||||
)
|
||||
|
||||
Link.list(
|
||||
:link_object => 'Ticket',
|
||||
:link_object_value => 1
|
||||
)
|
||||
|
||||
Link.get_links_for_source_object(
|
||||
|
@ -41,34 +47,73 @@ class Link < ActiveRecord::Base
|
|||
Link.delete_all_links_by_value( :object_value => 1 )
|
||||
=end
|
||||
|
||||
def self.list(data)
|
||||
linkobject = self.link_object_get( :name => data[:link_object] )
|
||||
return if !linkobject
|
||||
list = Link.where(
|
||||
'link_object_source_id = ? AND link_object_source_value = ?', linkobject.id, data[:link_object_value]
|
||||
)
|
||||
|
||||
map = {
|
||||
'normal' => 'normal',
|
||||
'parent' => 'child',
|
||||
'child' => 'parent',
|
||||
}
|
||||
|
||||
items = []
|
||||
list.each { |item|
|
||||
link = {}
|
||||
link['link_type'] = map[ Link::Type.find( item.link_type_id ).name ]
|
||||
link['link_object'] = Link::Object.find( item.link_object_target_id ).name
|
||||
link['link_object_value'] = item.link_object_target_value
|
||||
items.push link
|
||||
}
|
||||
|
||||
list = Link.where(
|
||||
'link_object_target_id = ? AND link_object_target_value = ?', linkobject.id, data[:link_object_value]
|
||||
)
|
||||
list.each { |item|
|
||||
link = {}
|
||||
link['link_type'] = Link::Type.find( item.link_type_id ).name
|
||||
link['link_object'] = Link::Object.find( item.link_object_source_id ).name
|
||||
link['link_object_value'] = item.link_object_source_value
|
||||
items.push link
|
||||
}
|
||||
|
||||
return items
|
||||
end
|
||||
|
||||
def self.get_links_for_source_object(data)
|
||||
linkobject_id = self.get_linktype_by_name( :name => data[:link_object] )
|
||||
if linkobject_id
|
||||
where( :link_object_source_id => linkobject_id, :link_object_source_value => data[:link_object_value] )
|
||||
Link.where( :link_object_source_id => linkobject_id, :link_object_source_value => data[:link_object_value] )
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_links_for_target_object(data)
|
||||
linkobject_id = self.get_linktype_by_name( :name => data[:link_object] )
|
||||
if linkobject_id
|
||||
where( :link_object_target_id => linkobject_id, :link_object_target_value => data[:link_object_value] )
|
||||
Link.where( :link_object_target_id => linkobject_id, :link_object_target_value => data[:link_object_value] )
|
||||
end
|
||||
end
|
||||
|
||||
def self.add(data)
|
||||
if data.has_key?(:link_object_source)
|
||||
|
||||
# it exists we have to delete it
|
||||
linkobject_id = self.get_linktype_by_name( :name => data[:link_object_source] )
|
||||
data[:link_object_source_id] = linkobject_id
|
||||
if data.has_key?(:link_type)
|
||||
linktype = self.link_type_get( :name => data[:link_type] )
|
||||
data[:link_type_id] = linktype.id
|
||||
data.delete( :link_type )
|
||||
end
|
||||
|
||||
if data.has_key?(:link_object_source)
|
||||
linkobject = self.link_object_get( :name => data[:link_object_source] )
|
||||
data[:link_object_source_id] = linkobject.id
|
||||
data.delete( :link_object_source )
|
||||
end
|
||||
|
||||
|
||||
if data.has_key?(:link_object_target)
|
||||
# it exists we have to delete it
|
||||
linkobject_id = self.get_linktype_by_name( :name => data[:link_object_target] )
|
||||
data[:link_object_target_id] = linkobject_id
|
||||
linkobject = self.link_object_get( :name => data[:link_object_target] )
|
||||
data[:link_object_target_id] = linkobject.id
|
||||
data.delete( :link_object_target )
|
||||
end
|
||||
|
||||
|
@ -87,16 +132,29 @@ class Link < ActiveRecord::Base
|
|||
Link.where( ["link_object_source_value = ? or link_object_target_value = ?", data[:object_value], data[:object_value]] ).destroy_all
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def self.get_linktype_by_name(data)
|
||||
linkid = Link::Object.where(:name=>data[:name]).first
|
||||
if linkid
|
||||
return linkid.id
|
||||
else
|
||||
return nil
|
||||
def self.link_type_get(data)
|
||||
linktype = Link::Type.where( :name => data[:name] ).first
|
||||
if !linktype
|
||||
linktype = Link::Type.create(
|
||||
:name => data[:name]
|
||||
)
|
||||
end
|
||||
return linkid
|
||||
return linktype
|
||||
end
|
||||
|
||||
def self.link_object_get(data)
|
||||
linkobject = Link::Object.where( :name => data[:name] ).first
|
||||
if !linkobject
|
||||
linkobject = Link::Object.create(
|
||||
:name => data[:name]
|
||||
)
|
||||
end
|
||||
return linkobject
|
||||
end
|
||||
|
||||
def self.get_linktype_by_name(data)
|
||||
linkid = Link::Object.where( :name => data[:name] ).first
|
||||
end
|
||||
|
||||
#checks for a valid link type
|
||||
|
|
|
@ -64,12 +64,19 @@ class Ticket < ApplicationModel
|
|||
# add history to both
|
||||
|
||||
# link tickets
|
||||
Link.add(
|
||||
:link_type => 'parent',
|
||||
:link_object_source => 'Ticket',
|
||||
:link_object_source_value => data[:ticket_id],
|
||||
:link_object_target => 'Ticket',
|
||||
:link_object_target_value => self.id
|
||||
)
|
||||
|
||||
# set state to 'merged'
|
||||
self.ticket_state_id = Ticket::State.where( :name => 'merged' ).first.id
|
||||
|
||||
# rest owner
|
||||
self.owner_id = User.where(:login => '-').first.id
|
||||
self.owner_id = User.where( :login => '-' ).first.id
|
||||
|
||||
# save ticket
|
||||
self.save
|
||||
|
|
|
@ -20,13 +20,18 @@ module ExtraRoutes
|
|||
|
||||
# templates
|
||||
map.resources :templates
|
||||
|
||||
|
||||
# links
|
||||
map.match '/links', :to => 'links#index'
|
||||
map.match '/links/add', :to => 'links#add'
|
||||
map.match '/links/delete', :to => 'links#delete'
|
||||
|
||||
# overviews
|
||||
map.resources :overviews
|
||||
|
||||
|
||||
# getting_started
|
||||
map.match '/getting_started', :to => 'getting_started#index'
|
||||
|
||||
|
||||
# rss
|
||||
map.match '/rss_fetch', :to => 'rss#fetch'
|
||||
end
|
||||
|
|
|
@ -103,6 +103,7 @@ class CreateTicket < ActiveRecord::Migration
|
|||
t.column :to, :string, :limit => 3000, :null => true
|
||||
t.column :cc, :string, :limit => 3000, :null => true
|
||||
t.column :subject, :string, :limit => 3000, :null => true
|
||||
# t.column :reply_to, :string, :limit => 3000, :null => true
|
||||
t.column :message_id, :string, :limit => 3000, :null => true
|
||||
t.column :message_id_md5, :string, :limit => 32, :null => true
|
||||
t.column :in_reply_to, :string, :limit => 3000, :null => true
|
||||
|
@ -186,7 +187,7 @@ class CreateTicket < ActiveRecord::Migration
|
|||
add_index :link_objects, [:name], :unique => true
|
||||
|
||||
create_table :links do |t|
|
||||
t.references :link_types, :null => false
|
||||
t.references :link_type, :null => false
|
||||
t.column :link_object_source_id, :integer, :null => false
|
||||
t.column :link_object_source_value, :integer, :null => false
|
||||
t.column :link_object_target_id, :integer, :null => false
|
||||
|
|
Loading…
Reference in a new issue