Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskonsite-архив-перенесен
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitry Korolev
taskonsite-архив-перенесен
Commits
119ec16e
Commit
119ec16e
authored
Mar 14, 2016
by
Олег Гиммельшпах
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attachments in redmine module
parent
2ca21ed0
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
175 additions
and
26 deletions
+175
-26
common/modules/support/controllers/DefaultController.php
common/modules/support/controllers/DefaultController.php
+0
-8
common/modules/support/controllers/SupportController.php
common/modules/support/controllers/SupportController.php
+76
-17
common/modules/support/models/redmine/Issue.php
common/modules/support/models/redmine/Issue.php
+3
-0
common/modules/support/models/redmine/RedmineHelper.php
common/modules/support/models/redmine/RedmineHelper.php
+13
-0
common/modules/support/views/support/_file.php
common/modules/support/views/support/_file.php
+15
-0
common/modules/support/views/support/create.php
common/modules/support/views/support/create.php
+7
-1
frontend/web/css/custom.css
frontend/web/css/custom.css
+5
-0
frontend/web/js/support.js
frontend/web/js/support.js
+56
-0
No files found.
common/modules/support/controllers/DefaultController.php
View file @
119ec16e
...
...
@@ -42,14 +42,6 @@ class DefaultController extends Controller
];
}
public
static
function
actionsTitles
()
{
return
[
'Login'
=>
'Авторизация'
,
'Logout'
=>
'Выход'
,
];
}
public
function
actionLogin
()
{
$this
->
page_title
=
'Техническая поддержка'
;
...
...
common/modules/support/controllers/SupportController.php
View file @
119ec16e
...
...
@@ -6,10 +6,12 @@ use Yii;
use
yii\filters\AccessControl
;
use
yii\helpers\ArrayHelper
;
use
yii\web\Controller
;
use
yii\web\Response
;
use
yii\web\NotFoundHttpException
;
use
common\models\Settings
;
use
common\modules\support\models\redmine\Issue
;
use
common\modules\support\models\redmine\RedmineHelper
;
/**
* Default controller for the `support` module
...
...
@@ -26,11 +28,11 @@ class SupportController extends Controller
'access'
=>
[
'class'
=>
AccessControl
::
className
(),
'user'
=>
'support'
,
'only'
=>
[
'index'
],
'only'
=>
[
'index'
,
'create'
,
'view'
,
'file'
],
'rules'
=>
[
[
'allow'
=>
true
,
'actions'
=>
[
'index'
],
'actions'
=>
[
'index'
,
'create'
,
'view'
,
'file'
],
'roles'
=>
[
'@'
],
],
],
...
...
@@ -38,13 +40,6 @@ class SupportController extends Controller
];
}
public
static
function
actionsTitles
()
{
return
[
'Index'
=>
'Техническая поддержка'
,
];
}
public
function
actionIndex
()
{
$client
=
$this
->
getClient
();
...
...
@@ -73,6 +68,8 @@ class SupportController extends Controller
public
function
actionCreate
()
{
$this
->
view
->
registerJsFile
(
'/js/support.js'
,
[
'position'
=>
yii\web\View
::
POS_END
]);
$model
=
new
Issue
();
$client
=
$this
->
getClient
();
...
...
@@ -81,7 +78,7 @@ class SupportController extends Controller
if
(
$model
->
load
(
Yii
::
$app
->
request
->
post
())
&&
$model
->
validate
())
{
$
client
->
issue
->
create
(
[
$
params
=
[
'subject'
=>
$model
->
subject
,
'description'
=>
$model
->
description
,
'project_id'
=>
$model
->
project_id
,
...
...
@@ -89,17 +86,79 @@ class SupportController extends Controller
'status_id'
=>
$model
->
status_id
,
'tracker_id'
=>
$model
->
tracker_id
,
'author_id'
=>
$user
[
'user'
][
'id'
]
];
if
(
$model
->
files
)
{
$uploads
=
[];
foreach
(
$model
->
files
as
$file
)
{
$uploads
[]
=
[
'token'
=>
$file
[
'token'
],
'filename'
=>
$file
[
'filename'
],
'content_type'
=>
$file
[
'type'
],
];
}
$params
=
ArrayHelper
::
merge
(
$params
,
[
'uploads'
=>
$uploads
]);
}
$client
->
issue
->
create
(
$params
);
return
$this
->
redirect
([
'/support'
]);
}
else
{
return
$this
->
render
(
'create'
,
[
'model'
=>
$model
,
'user'
=>
$user
]);
}
public
function
actionFile
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
try
{
if
(
$_FILES
[
'files'
])
{
$html
=
''
;
foreach
(
$_FILES
[
'files'
][
'name'
]
as
$i
=>
$name
)
{
$client
=
$this
->
getClient
();
$response
=
json_decode
(
$client
->
attachment
->
upload
(
@
file_get_contents
(
$_FILES
[
'files'
][
'tmp_name'
][
$i
])));
$html
.=
$this
->
renderPartial
(
'_file'
,
[
'name'
=>
$name
,
'size'
=>
RedmineHelper
::
formatSize
(
$_FILES
[
'files'
][
'size'
][
$i
]),
'token'
=>
$response
->
upload
->
token
,
'type'
=>
$_FILES
[
'files'
][
'type'
][
$i
]
]);
}
return
[
'html'
=>
$html
,
'success'
=>
true
];
}
}
catch
(
Exception
$e
)
{
return
[
'success'
=>
false
];
}
return
[
'success'
=>
false
];
}
else
{
throw
new
NotFoundHttpException
(
'Доступ запрещен!'
);
}
}
public
function
actionView
(
$id
)
...
...
common/modules/support/models/redmine/Issue.php
View file @
119ec16e
...
...
@@ -14,6 +14,8 @@ class Issue extends yii\base\Model
public
$tracker_id
=
self
::
TRACKER_NONE
;
public
$status_id
=
self
::
STATUS_NEW
;
public
$files
=
null
;
const
PRIORITY_SIMPLE
=
2
;
const
PRIORITY_FIRE
=
3
;
...
...
@@ -30,6 +32,7 @@ class Issue extends yii\base\Model
[[
'tracker_id'
,
'project_id'
,
'status_id'
,
'priority_id'
,
'description'
],
'required'
],
[[
'tracker_id'
,
'project_id'
,
'status_id'
,
'priority_id'
],
'integer'
],
[[
'description'
],
'string'
],
[[
'files'
],
'safe'
],
[[
'subject'
],
'string'
,
'max'
=>
255
],
];
}
...
...
common/modules/support/models/redmine/RedmineHelper.php
View file @
119ec16e
...
...
@@ -78,4 +78,17 @@ class RedmineHelper
return
$memberships
;
}
public
static
function
formatSize
(
$value
)
{
$units
=
array
(
'B'
,
'KB'
,
'MB'
,
'GB'
,
'TB'
);
$base
=
1024
;
for
(
$i
=
0
;
$base
<=
$value
;
$i
++
)
{
$value
=
$value
/
$base
;
}
return
round
(
$value
,
2
)
.
' '
.
$units
[
$i
];
}
}
\ No newline at end of file
common/modules/support/views/support/_file.php
0 → 100644
View file @
119ec16e
<?php
$id
=
uniqid
();
?>
<div
class=
"file_box_wr"
>
<span
class=
"glyphicon glyphicon-file"
></span>
<span>
<?=
$name
?>
</span>
<span
class=
"color_gray"
>
<?=
$size
?>
</span>
<a
class=
"delete-file"
href=
"#"
><span
class=
"glyphicon glyphicon-remove color_gray"
></span></a>
<input
type=
"hidden"
name=
"Issue[files][
<?=
$id
?>
][token]"
value=
"
<?=
$token
?>
"
>
<input
type=
"hidden"
name=
"Issue[files][
<?=
$id
?>
][filename]"
value=
"
<?=
$name
?>
"
>
<input
type=
"hidden"
name=
"Issue[files][
<?=
$id
?>
][type]"
value=
"
<?=
$type
?>
"
>
</div>
\ No newline at end of file
common/modules/support/views/support/create.php
View file @
119ec16e
...
...
@@ -139,7 +139,13 @@ use common\modules\support\models\redmine\RedmineHelper;
<div
class=
"col-sm-12"
>
<button
class=
"gray_button"
>
Прикрепить файл
<i
class=
"glyphicon glyphicon-paperclip"
></i></button>
<div
id=
"file-container"
>
</div>
<input
type=
"file"
id=
"file-attachment-input"
style=
"display:none;"
multiple=
"multiple"
>
<div
class=
"gray_button attachment-button"
>
Прикрепить файл
<i
class=
"glyphicon glyphicon-paperclip"
></i></div>
<br>
<?=
Html
::
submitButton
(
'Создать задачу'
,
[
'class'
=>
'btn btn-success-2'
])
?>
...
...
frontend/web/css/custom.css
View file @
119ec16e
...
...
@@ -1800,3 +1800,8 @@ a.keys_test_btn {
.keys_block_small
{
display
:
block
;
}
.attachment-button
{
display
:
inline-block
;
cursor
:
pointer
;
}
\ No newline at end of file
frontend/web/js/support.js
0 → 100644
View file @
119ec16e
$
(
function
(){
$
(
'
.attachment-button
'
).
click
(
function
(){
$
(
'
#file-attachment-input
'
).
trigger
(
'
click
'
);
});
$
(
'
#file-attachment-input
'
).
change
(
function
(){
var
xhr
=
new
XMLHttpRequest
,
data
=
new
FormData
(),
files
=
$
(
'
#file-attachment-input
'
)[
0
].
files
;
xhr
.
open
(
"
POST
"
,
'
/support/file
'
,
true
);
xhr
.
setRequestHeader
(
"
X-Requested-With
"
,
"
XMLHttpRequest
"
);
data
.
append
(
"
_csrf
"
,
$
(
'
meta[name="csrf-token"]
'
).
attr
(
'
content
'
));
$
.
each
(
files
,
function
(
i
,
file
){
data
.
append
(
"
files[]
"
,
file
);
});
xhr
.
send
(
data
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
{
try
{
var
response
=
JSON
.
parse
(
xhr
.
responseText
);
}
catch
(
e
)
{
var
response
=
xhr
.
responseText
;
}
if
(
response
.
success
)
{
$
(
'
#file-container
'
).
append
(
response
.
html
);
}
}
}
$
(
this
).
val
(
''
);
});
$
(
document
).
delegate
(
'
.file_box_wr .delete-file
'
,
'
click
'
,
function
(){
$
(
this
).
closest
(
'
.file_box_wr
'
).
remove
();
return
false
;
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment