Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
ulakbus-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ulakbus
ulakbus-ui
Commits
6a71c692
Commit
6a71c692
authored
Aug 08, 2016
by
Vladimir Baranov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rref #5392. Add message editor
parent
d98c5e65
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
180 additions
and
17 deletions
+180
-17
app.css
app/app.css
+4
-3
messaging.js
app/components/messaging/messaging.js
+100
-3
messaging_service.js
app/components/messaging/messaging_service.js
+25
-8
conversation.html
app/components/messaging/templates/conversation.html
+1
-1
edit_message.html
app/components/messaging/templates/edit_message.html
+5
-0
directives.js
app/shared/directives.js
+29
-0
error_service.js
app/zetalib/error_service.js
+2
-1
utils_service.js
app/zetalib/utils_service.js
+14
-1
No files found.
app/app.css
View file @
6a71c692
...
@@ -2480,6 +2480,7 @@ table.dataTable thead .sorting:after {
...
@@ -2480,6 +2480,7 @@ table.dataTable thead .sorting:after {
.chat-app
.conversation-section
.user-message
.message-content
{
.chat-app
.conversation-section
.user-message
.message-content
{
font-family
:
'robotomedium'
;
font-family
:
'robotomedium'
;
position
:
relative
;
}
}
.chat-app
.conversation-section
.message-content-url
{
.chat-app
.conversation-section
.message-content-url
{
...
@@ -2576,14 +2577,14 @@ table.dataTable thead .sorting:after {
...
@@ -2576,14 +2577,14 @@ table.dataTable thead .sorting:after {
opacity
:
1
;
opacity
:
1
;
}
}
.chat-app
.conversation-section
.user-message
.edit-text-message
input
{
.chat-app
.conversation-section
.user-message
.edit-text-message
.editor
{
width
:
100%
;
width
:
100%
;
margin-bottom
:
7px
;
margin-bottom
:
7px
;
margin-top
:
7px
;
margin-top
:
7px
;
height
:
30px
;
border-radius
:
3px
;
border-radius
:
3px
;
border
:
1px
solid
#ccc
;
border
:
1px
solid
#ccc
;
padding
-left
:
7
px
;
padding
:
5px
10
px
;
outline
:
none
;
outline
:
none
;
}
}
...
...
app/components/messaging/messaging.js
View file @
6a71c692
angular
.
module
(
"ulakbus.messaging"
)
angular
.
module
(
"ulakbus.messaging"
)
.
directive
(
'messaging'
,
function
(
Generator
,
MessagingService
,
$log
,
$rootScope
,
MessagingPopup
,
Utils
,
$q
)
{
.
directive
(
'messaging'
,
function
(
Generator
,
MessagingService
,
$log
,
$rootScope
,
MessagingPopup
,
Utils
,
$q
,
$timeout
)
{
// get channel key
// get channel key
function
getKey
(
channel
)
{
function
getKey
(
channel
)
{
...
@@ -79,11 +79,21 @@ angular.module("ulakbus.messaging")
...
@@ -79,11 +79,21 @@ angular.module("ulakbus.messaging")
if
(
channel
.
messages
){
if
(
channel
.
messages
){
channel
.
messages
.
push
(
message
);
channel
.
messages
.
push
(
message
);
}
}
}
;
}
updateLastMessage
(
message
);
updateLastMessage
(
message
);
reportLastSeenMessage
();
reportLastSeenMessage
();
}
}
function
updateMessage
(
message
){
// update current channel messages only
if
(
message
.
channel_key
!=
getKey
(
iScope
.
selectedChannel
))
return
;
// update only visible messages
var
storedMessage
=
Utils
.
findWhere
(
iScope
.
selectedChannel
.
messages
,
{
key
:
message
.
key
})
if
(
storedMessage
){
angular
.
extend
(
storedMessage
,
message
)
}
}
function
updateAndSelect
(
channelKey
){
function
updateAndSelect
(
channelKey
){
channelKey
=
getKey
(
channelKey
);
channelKey
=
getKey
(
channelKey
);
return
iScope
.
updateChannelsList
().
then
(
function
(){
return
iScope
.
updateChannelsList
().
then
(
function
(){
...
@@ -276,6 +286,7 @@ angular.module("ulakbus.messaging")
...
@@ -276,6 +286,7 @@ angular.module("ulakbus.messaging")
iScope
.
applyMessageAction
=
function
(
message
,
action
){
iScope
.
applyMessageAction
=
function
(
message
,
action
){
var
actionView
=
action
[
1
];
var
actionView
=
action
[
1
];
switch
(
actionView
)
{
switch
(
actionView
)
{
case
"_zops_favorite_message"
:
case
"_zops_favorite_message"
:
MessagingService
.
add_to_favorites
(
message
.
key
)
MessagingService
.
add_to_favorites
(
message
.
key
)
.
then
(
function
(){
.
then
(
function
(){
...
@@ -283,6 +294,7 @@ angular.module("ulakbus.messaging")
...
@@ -283,6 +294,7 @@ angular.module("ulakbus.messaging")
message
.
actions
=
null
;
message
.
actions
=
null
;
});
});
break
;
break
;
case
"_zops_flag_message"
:
case
"_zops_flag_message"
:
MessagingService
.
flag_message
(
message
.
key
,
true
)
MessagingService
.
flag_message
(
message
.
key
,
true
)
.
then
(
function
(){
.
then
(
function
(){
...
@@ -290,6 +302,7 @@ angular.module("ulakbus.messaging")
...
@@ -290,6 +302,7 @@ angular.module("ulakbus.messaging")
message
.
actions
=
null
;
message
.
actions
=
null
;
});
});
break
;
break
;
case
"_zops_unflag_message"
:
case
"_zops_unflag_message"
:
MessagingService
.
flag_message
(
message
.
key
,
false
)
MessagingService
.
flag_message
(
message
.
key
,
false
)
.
then
(
function
(){
.
then
(
function
(){
...
@@ -297,6 +310,7 @@ angular.module("ulakbus.messaging")
...
@@ -297,6 +310,7 @@ angular.module("ulakbus.messaging")
message
.
actions
=
null
;
message
.
actions
=
null
;
});
});
break
;
break
;
case
"_zops_delete_message"
:
case
"_zops_delete_message"
:
iScope
.
deleteConfirmation
(
"Mesajı silmek istediğinize emin misiniz?"
)
iScope
.
deleteConfirmation
(
"Mesajı silmek istediğinize emin misiniz?"
)
.
then
(
function
(){
.
then
(
function
(){
...
@@ -305,7 +319,31 @@ angular.module("ulakbus.messaging")
...
@@ -305,7 +319,31 @@ angular.module("ulakbus.messaging")
})
})
});
});
break
;
break
;
case
"_zops_edit_message"
:
case
"_zops_edit_message"
:
// find message content container
var
messageContainer
=
$
(
"#msg-"
+
message
.
key
);
MessagingPopup
.
show
({
templateUrl
:
"components/messaging/templates/edit_message.html"
,
rootElement
:
messageContainer
,
// activate inplace editor logic
inplaceEditor
:
true
,
link
:
function
(
scope
)
{
scope
.
internalContent
=
scope
.
content
;
scope
.
save
=
function
(){
// delete message if new content is empty
if
(
!
scope
.
internalContent
){
return
iScope
.
applyMessageAction
(
message
,
[
'_'
,
'_zops_delete_message'
]);
}
MessagingService
.
edit_message
(
message
.
key
,
scope
.
internalContent
)
.
then
(
function
(){
// apply changes to element
scope
.
content
=
scope
.
internalContent
;
scope
.
done
();
});
};
}
});
break
;
break
;
}
}
};
};
...
@@ -319,7 +357,11 @@ angular.module("ulakbus.messaging")
...
@@ -319,7 +357,11 @@ angular.module("ulakbus.messaging")
// listen to new messages and add them to selected channel if any
// listen to new messages and add them to selected channel if any
$rootScope
.
$on
(
"message"
,
function
(
e
,
message
){
$rootScope
.
$on
(
"message"
,
function
(
e
,
message
){
appendMessage
(
iScope
.
selectedChannel
,
MessagingService
.
prepareMessage
(
message
));
if
(
message
.
is_update
){
updateMessage
(
message
);
}
else
{
appendMessage
(
iScope
.
selectedChannel
,
MessagingService
.
prepareMessage
(
message
));
}
});
});
// notifications in messaging window are processed as ordinary messages
// notifications in messaging window are processed as ordinary messages
$rootScope
.
$on
(
"notifications"
,
function
(
e
,
notification
){
$rootScope
.
$on
(
"notifications"
,
function
(
e
,
notification
){
...
@@ -371,3 +413,58 @@ angular.module("ulakbus.messaging")
...
@@ -371,3 +413,58 @@ angular.module("ulakbus.messaging")
}
}
}
}
})
})
.
directive
(
"contenteditable"
,
function
(){
return
{
require
:
"?ngModel"
,
scope
:
{},
link
:
function
(
iScope
,
iElem
,
iAttrs
,
ngModel
)
{
if
(
!
ngModel
)
return
;
ngModel
.
$render
=
function
()
{
iElem
.
text
(
ngModel
.
$viewValue
||
''
);
};
// Listen for change events to enable binding
iElem
.
on
(
'blur keyup change'
,
function
()
{
iScope
.
$evalAsync
(
read
);
});
function
read
()
{
var
html
=
iElem
.
text
();
ngModel
.
$setViewValue
(
html
);
}
iScope
.
$on
(
'$destroy'
,
function
(){
iElem
.
off
(
'blur keyup change'
);
})
}
}
})
.
directive
(
'autoFocus'
,
function
(
$timeout
){
function
placeCaretAtEnd
(
el
)
{
el
.
focus
();
if
(
typeof
window
.
getSelection
!=
"undefined"
&&
typeof
document
.
createRange
!=
"undefined"
)
{
var
range
=
document
.
createRange
();
range
.
selectNodeContents
(
el
);
range
.
collapse
(
false
);
var
sel
=
window
.
getSelection
();
sel
.
removeAllRanges
();
sel
.
addRange
(
range
);
}
else
if
(
typeof
document
.
body
.
createTextRange
!=
"undefined"
)
{
var
textRange
=
document
.
body
.
createTextRange
();
textRange
.
moveToElementText
(
el
);
textRange
.
collapse
(
false
);
textRange
.
select
();
}
}
return
{
link
:
function
(
iScope
,
iElem
){
$timeout
(
function
(){
placeCaretAtEnd
(
iElem
[
0
]);
},
500
);
}
}
});
app/components/messaging/messaging_service.js
View file @
6a71c692
...
@@ -71,6 +71,10 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -71,6 +71,10 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
if
(
!
messagingAppIsHidden
&&
message
.
channel_key
==
currentChannelKey
){
if
(
!
messagingAppIsHidden
&&
message
.
channel_key
==
currentChannelKey
){
return
;
return
;
}
}
// skip message updates
if
(
message
.
is_update
)
return
;
checkIfInitialized
().
then
(
function
(){
checkIfInitialized
().
then
(
function
(){
var
channel
=
channelsMap
[
message
.
channel_key
];
var
channel
=
channelsMap
[
message
.
channel_key
];
if
(
channel
){
if
(
channel
){
...
@@ -534,11 +538,12 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -534,11 +538,12 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
var
resultDeferred
=
$q
.
defer
();
var
resultDeferred
=
$q
.
defer
();
var
scope
=
config
.
scope
||
$rootScope
.
$new
(
true
);
var
scope
=
config
.
scope
||
$rootScope
.
$new
(
true
);
var
rootElement
=
config
.
rootElement
;
var
rootElement
=
config
.
rootElement
;
var
element
=
$compile
(
template
)(
scope
);
var
originalContent
,
element
;
if
(
config
.
link
){
config
.
link
(
scope
);
}
if
(
config
.
inplaceEditor
){
originalContent
=
rootElement
.
text
();
scope
.
content
=
originalContent
;
}
scope
.
done
=
function
(
result
){
scope
.
done
=
function
(
result
){
resultDeferred
.
resolve
.
apply
(
this
,
arguments
);
resultDeferred
.
resolve
.
apply
(
this
,
arguments
);
};
};
...
@@ -546,14 +551,26 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -546,14 +551,26 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
resultDeferred
.
reject
.
apply
(
this
,
arguments
);
resultDeferred
.
reject
.
apply
(
this
,
arguments
);
};
};
if
(
config
.
link
){
config
.
link
(
scope
);
}
element
=
$compile
(
template
)(
scope
);
rootElement
.
empty
();
rootElement
.
empty
();
rootElement
.
append
(
element
);
rootElement
.
append
(
element
);
resultDeferred
.
promise
.
_done
=
scope
.
done
;
resultDeferred
.
promise
.
_done
=
scope
.
done
;
resultDeferred
.
promise
.
_cancel
=
scope
.
cancel
;
resultDeferred
.
promise
.
_cancel
=
scope
.
cancel
;
return
resultDeferred
.
promise
.
finally
(
function
(){
return
resultDeferred
.
promise
rootElement
.
empty
();
.
finally
(
function
(){
scope
.
$destroy
();
// inplace editor can change scope.content and it will be applied to original rootElement
if
(
config
.
inplaceEditor
){
rootElement
.
text
(
scope
.
content
);
}
else
{
rootElement
.
empty
();
}
scope
.
$destroy
();
});
});
}
}
...
@@ -566,4 +583,4 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
...
@@ -566,4 +583,4 @@ angular.module('ulakbus.messaging', ['ui.bootstrap'])
return
compile
(
config
.
template
,
config
);
return
compile
(
config
.
template
,
config
);
};
};
})
;
})
app/components/messaging/templates/conversation.html
View file @
6a71c692
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
<div
class=
"message-time"
>
{{::msg.moment|fromNow}}
</div>
<div
class=
"message-time"
>
{{::msg.moment|fromNow}}
</div>
</div>
</div>
<div
class=
"message-content"
>
<div
class=
"message-content"
>
{{::msg.content}}
<div
class=
"editable-message-content"
id=
"msg-{{msg.key}}"
>
{{msg.content}}
</div>
<a
class=
"message-content-url"
href=
"{{::msg.url}}"
ng-click=
"hideApp()"
ng-if=
"msg.url"
>
{{msg.url}}
</a>
<a
class=
"message-content-url"
href=
"{{::msg.url}}"
ng-click=
"hideApp()"
ng-if=
"msg.url"
>
{{msg.url}}
</a>
</div>
</div>
</div>
</div>
...
...
app/components/messaging/templates/edit_message.html
0 → 100644
View file @
6a71c692
<div
class=
"edit-text-message"
>
<div
class=
"editor"
contenteditable=
""
auto-focus
on-enter-pressed=
"save()"
on-esc-pressed=
"cancel()"
ng-model=
"internalContent"
></div>
<button
class=
"btn btn-default"
ng-click=
"cancel()"
>
Cancel
</button>
<button
class=
"btn btn-success"
ng-click=
"save()"
>
Save Changes
</button>
</div>
app/shared/directives.js
View file @
6a71c692
...
@@ -684,6 +684,35 @@ angular.module('ulakbus')
...
@@ -684,6 +684,35 @@ angular.module('ulakbus')
});
});
event
.
preventDefault
();
event
.
preventDefault
();
}
}
});
scope
.
$on
(
'$destroy'
,
function
(){
element
.
unbind
(
'keydown keypress'
);
})
}
}
})
/**
* @memberof ulakbus
* @ngdoc directive
* @name onEscPressed
* @description Fire action when ESC pressed on element
*/
.
directive
(
"onEscPressed"
,
function
()
{
return
{
link
:
function
(
scope
,
element
,
attrs
)
{
element
.
bind
(
"keydown keypress"
,
function
(
event
)
{
if
(
event
.
which
===
27
)
{
scope
.
$apply
(
function
(){
scope
.
$eval
(
attrs
.
onEscPressed
);
});
event
.
preventDefault
();
}
});
scope
.
$on
(
'$destroy'
,
function
(){
element
.
unbind
(
'keydown keypress'
);
})
})
}
}
}
}
...
...
app/zetalib/error_service.js
View file @
6a71c692
...
@@ -102,6 +102,7 @@ angular.module('ulakbus')
...
@@ -102,6 +102,7 @@ angular.module('ulakbus')
if
(
$location
.
path
()
===
"/login"
)
{
if
(
$location
.
path
()
===
"/login"
)
{
$log
.
debug
(
"show errors on login form"
);
$log
.
debug
(
"show errors on login form"
);
}
else
{
}
else
{
alert
(
"Want relogin!"
);
return
window
.
location
.
reload
();
return
window
.
location
.
reload
();
}
}
},
},
...
@@ -129,4 +130,4 @@ angular.module('ulakbus')
...
@@ -129,4 +130,4 @@ angular.module('ulakbus')
};
};
return
error_service
;
return
error_service
;
});
});
\ No newline at end of file
app/zetalib/utils_service.js
View file @
6a71c692
...
@@ -14,7 +14,7 @@ angular.module("ulakbus")
...
@@ -14,7 +14,7 @@ angular.module("ulakbus")
// check if obj1 has properties values equal to corresponding properties in obj2
// check if obj1 has properties values equal to corresponding properties in obj2
function
hasEqualProperties
(
obj1
,
obj2
){
function
hasEqualProperties
(
obj1
,
obj2
){
var
result
=
true
var
result
=
true
;
for
(
var
prop
in
obj2
){
for
(
var
prop
in
obj2
){
if
(
obj2
.
hasOwnProperty
(
prop
)){
if
(
obj2
.
hasOwnProperty
(
prop
)){
result
=
result
&&
obj2
[
prop
]
==
obj1
[
prop
];
result
=
result
&&
obj2
[
prop
]
==
obj1
[
prop
];
...
@@ -50,6 +50,19 @@ angular.module("ulakbus")
...
@@ -50,6 +50,19 @@ angular.module("ulakbus")
return
list
[
i
];
return
list
[
i
];
}
}
}
}
};
/**
* @param list {Array} Array of objects to group
* @param condition {Object} conditions object. If object in collection has same values as in conditions object found object will be returned
* @returns {Object}|undefined
*/
this
.
findWhere
=
function
(
list
,
condition
){
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
){
if
(
hasEqualProperties
(
list
[
i
],
condition
)){
return
list
[
i
];
}
}
}
}
/**
/**
...
...
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