| 1 |
require 'adapters/drupal/idrupal' |
| 2 |
|
| 3 |
require 'Qt4' |
| 4 |
|
| 5 |
class SitePage < Qt::Widget |
| 6 |
|
| 7 |
slots :fetchIssueList, :refreshView, :updateIssueList |
| 8 |
|
| 9 |
attr_reader :widget |
| 10 |
|
| 11 |
attr_reader :username |
| 12 |
attr_reader :password |
| 13 |
attr_reader :site |
| 14 |
attr_reader :name |
| 15 |
|
| 16 |
attr_reader :adapter |
| 17 |
|
| 18 |
attr_reader :configureAction |
| 19 |
attr_reader :createIssueAction |
| 20 |
attr_reader :editCurrentAction |
| 21 |
attr_reader :viewCurrentAction |
| 22 |
|
| 23 |
def initialize( name, parent ) |
| 24 |
super parent |
| 25 |
|
| 26 |
@name = name |
| 27 |
@site = "" |
| 28 |
@username = "" |
| 29 |
@password = "" |
| 30 |
|
| 31 |
@adapter = IDrupal.new( self ) |
| 32 |
|
| 33 |
connect( @adapter, SIGNAL(:filterUpdated), self, SLOT(:refreshView) ) |
| 34 |
connect( @adapter, SIGNAL(:issueListUpdated), self, SLOT(:updateIssueList) ) |
| 35 |
|
| 36 |
createActions |
| 37 |
createUI |
| 38 |
updateFilters |
| 39 |
updateIssueList |
| 40 |
end |
| 41 |
|
| 42 |
def fetchIssueList |
| 43 |
selectedStatus = @statusSelect.itemData( @statusSelect.currentIndex, Qt::UserRole ).toString |
| 44 |
selectedPriority = @prioritySelect.itemData( @prioritySelect.currentIndex, Qt::UserRole ).toString |
| 45 |
selectedCategory = @categorySelect.itemData( @categorySelect.currentIndex, Qt::UserRole ).toString |
| 46 |
@adapter.updateIssueList( selectedStatus, selectedPriority, selectedCategory ) |
| 47 |
end |
| 48 |
|
| 49 |
def updateIssueList |
| 50 |
@issues.columnCount = 8 |
| 51 |
@issues.rowCount = @adapter.issues.size |
| 52 |
|
| 53 |
@issues.setHorizontalHeaderLabels( ["Project", "Title", "Status", |
| 54 |
"Priority", "Category", "Replies", |
| 55 |
"Last Updated", "Assigned to"] ) |
| 56 |
|
| 57 |
verticalLabels = [] |
| 58 |
|
| 59 |
for i in (0..@issues.rowCount-1) do |
| 60 |
verticalLabels.push( @adapter.issues[ i ][:node] ) |
| 61 |
|
| 62 |
project = Qt::TableWidgetItem.new( @adapter.issues[ i ][:project] ) |
| 63 |
title = Qt::TableWidgetItem.new( @adapter.issues[ i ][:title] ) |
| 64 |
status = Qt::TableWidgetItem.new( @adapter.issues[ i ][:status] ) |
| 65 |
priority = Qt::TableWidgetItem.new( @adapter.issues[ i ][:priority] ) |
| 66 |
category = Qt::TableWidgetItem.new( @adapter.issues[ i ][:category] ) |
| 67 |
replies = Qt::TableWidgetItem.new( @adapter.issues[ i ][:replies] ) |
| 68 |
last_updated = Qt::TableWidgetItem.new( @adapter.issues[ i ][:last_updated] ) |
| 69 |
assigned_to = Qt::TableWidgetItem.new( @adapter.issues[ i ][:assigned_to] ) |
| 70 |
|
| 71 |
@issues.setItem( i, 0, project ) |
| 72 |
@issues.setItem( i, 1, title ) |
| 73 |
@issues.setItem( i, 2, status ) |
| 74 |
@issues.setItem( i, 3, priority ) |
| 75 |
@issues.setItem( i, 4, category ) |
| 76 |
@issues.setItem( i, 5, replies ) |
| 77 |
@issues.setItem( i, 6, last_updated ) |
| 78 |
@issues.setItem( i, 7, assigned_to ) |
| 79 |
|
| 80 |
for j in (0..@issues.columnCount-1) do |
| 81 |
@issues.item(i, j).setFlags( @issues.item( i, j ).flags & (~Qt::ItemIsEditable) ) |
| 82 |
end |
| 83 |
end |
| 84 |
|
| 85 |
@issues.setVerticalHeaderLabels( verticalLabels ) |
| 86 |
end |
| 87 |
|
| 88 |
def refreshView |
| 89 |
updateFilters |
| 90 |
end |
| 91 |
|
| 92 |
def editSelectedIssue |
| 93 |
row = @issues.currentRow |
| 94 |
if row >= 0 then |
| 95 |
editIssue( @adapter.issues[ row ][ :node ] ) |
| 96 |
end |
| 97 |
end |
| 98 |
|
| 99 |
def viewSelectedIssue |
| 100 |
row = @issues.currentRow |
| 101 |
if row >= 0 then |
| 102 |
@adapter.viewIssueDetails( @adapter.issues[ row ][ :node ] ) |
| 103 |
end |
| 104 |
end |
| 105 |
|
| 106 |
private |
| 107 |
|
| 108 |
def createActions |
| 109 |
@configureAction = Qt::Action.new( @name, self ) |
| 110 |
@configureAction.connect( SIGNAL(:triggered) ) { @adapter.configure } |
| 111 |
|
| 112 |
@createIssueAction = Qt::Action.new( tr( "Create Issue" ), self ) |
| 113 |
@createIssueAction.connect( SIGNAL(:triggered) ) { @adapter.createIssue } |
| 114 |
|
| 115 |
@editCurrentAction = Qt::Action.new( tr( "Edit Selected Issue" ), self ) |
| 116 |
@editCurrentAction.connect( SIGNAL(:triggered) ) { editSelectedIssue } |
| 117 |
|
| 118 |
@viewCurrentAction = Qt::Action.new( tr( "View" ), self ) |
| 119 |
@viewCurrentAction.connect( SIGNAL(:triggered) ) { viewSelectedIssue } |
| 120 |
end |
| 121 |
|
| 122 |
def createUI |
| 123 |
@statusSelect = Qt::ComboBox.new |
| 124 |
@prioritySelect = Qt::ComboBox.new |
| 125 |
@categorySelect = Qt::ComboBox.new |
| 126 |
|
| 127 |
@updateListButton = Qt::PushButton.new( "Update" ) |
| 128 |
connect( @updateListButton, SIGNAL(:clicked), self, SLOT(:fetchIssueList) ) |
| 129 |
|
| 130 |
@filterLayout = Qt::HBoxLayout.new |
| 131 |
@filterLayout.addWidget( Qt::Label.new( "Status:" ) ) |
| 132 |
@filterLayout.addWidget( @statusSelect ) |
| 133 |
@filterLayout.addWidget( Qt::Label.new( "Priority:" ) ) |
| 134 |
@filterLayout.addWidget( @prioritySelect ) |
| 135 |
@filterLayout.addWidget( Qt::Label.new( "Category:" ) ) |
| 136 |
@filterLayout.addWidget( @categorySelect ) |
| 137 |
@filterLayout.addStretch |
| 138 |
@filterLayout.addWidget( @updateListButton ) |
| 139 |
|
| 140 |
@issues = Qt::TableWidget.new |
| 141 |
|
| 142 |
@mainLayout = Qt::VBoxLayout.new |
| 143 |
@mainLayout.addItem( @filterLayout ) |
| 144 |
@mainLayout.addWidget( @issues ) |
| 145 |
|
| 146 |
setLayout( @mainLayout ) |
| 147 |
end |
| 148 |
|
| 149 |
def updateFilters |
| 150 |
@statusSelect.clear |
| 151 |
@adapter.status_filter[ :items ].each do | item | |
| 152 |
@statusSelect.insertItem( @statusSelect.count, |
| 153 |
item[ :value ], |
| 154 |
Qt::Variant::fromValue( item[ :key ] ) ) |
| 155 |
if item[ :key ] == @adapter.status_filter[ :default ] then |
| 156 |
@statusSelect.currentIndex = @statusSelect.count - 1 |
| 157 |
end |
| 158 |
end |
| 159 |
|
| 160 |
@prioritySelect.clear |
| 161 |
@adapter.priority_filter[ :items ].each do | item | |
| 162 |
@prioritySelect.insertItem( @prioritySelect.count, |
| 163 |
item[ :value ], |
| 164 |
Qt::Variant::fromValue( item[ :key ] ) ) |
| 165 |
if item[ :key ] == @adapter.priority_filter[ :default ] then |
| 166 |
@prioritySelect.currentIndex = @prioritySelect.count - 1 |
| 167 |
end |
| 168 |
end |
| 169 |
|
| 170 |
@categorySelect.clear |
| 171 |
@adapter.category_filter[ :items ].each do | item | |
| 172 |
@categorySelect.insertItem( @categorySelect.count, |
| 173 |
item[ :value ], |
| 174 |
Qt::Variant::fromValue( item[ :key ] ) ) |
| 175 |
if item[ :key ] == @adapter.category_filter[ :default ] then |
| 176 |
@categorySelect.currentIndex = @categorySelect.count - 1 |
| 177 |
end |
| 178 |
end |
| 179 |
end |
| 180 |
|
| 181 |
def editIssue( node ) |
| 182 |
@adapter.editIssue( node ) |
| 183 |
end |
| 184 |
|
| 185 |
end |