Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
7083e8a0
Commit
7083e8a0
authored
Apr 05, 2018
by
Patrick O'Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrated segment_srv to ts
parent
32b833e4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
100 deletions
+100
-100
public/app/core/services/segment_srv.ts
+100
-100
No files found.
public/app/core/services/segment_srv.
j
s
→
public/app/core/services/segment_srv.
t
s
View file @
7083e8a0
define
([
'angular'
,
'lodash'
,
'../core_module'
,
],
function
(
angular
,
_
,
coreModule
)
{
'use strict'
;
coreModule
.
default
.
service
(
'uiSegmentSrv'
,
function
(
$sce
,
templateSrv
)
{
var
self
=
this
;
function
MetricSegment
(
options
)
{
if
(
options
===
'*'
||
options
.
value
===
'*'
)
{
this
.
value
=
'*'
;
this
.
html
=
$sce
.
trustAsHtml
(
'<i class="fa fa-asterisk"><i>'
);
this
.
type
=
options
.
type
;
this
.
expandable
=
true
;
return
;
}
if
(
_
.
isString
(
options
))
{
this
.
value
=
options
;
this
.
html
=
$sce
.
trustAsHtml
(
templateSrv
.
highlightVariablesAsHtml
(
this
.
value
));
return
;
}
import
_
from
'lodash'
;
import
coreModule
from
'../core_module'
;
// temp hack to work around legacy inconsistency in segment model
this
.
text
=
options
.
value
;
/** @ngInject */
export
function
uiSegmentSrv
(
$sce
,
templateSrv
)
{
let
self
=
this
;
this
.
cssClass
=
options
.
cssClass
;
this
.
custom
=
options
.
custom
;
this
.
type
=
options
.
type
;
this
.
fake
=
options
.
fake
;
this
.
value
=
options
.
value
;
this
.
selectMode
=
options
.
selectMode
;
function
MetricSegment
(
options
)
{
if
(
options
===
'*'
||
options
.
value
===
'*'
)
{
this
.
value
=
'*'
;
this
.
html
=
$sce
.
trustAsHtml
(
'<i class="fa fa-asterisk"><i>'
);
this
.
type
=
options
.
type
;
this
.
expandable
=
options
.
expandabl
e
;
this
.
html
=
options
.
html
||
$sce
.
trustAsHtml
(
templateSrv
.
highlightVariablesAsHtml
(
this
.
value
))
;
this
.
expandable
=
tru
e
;
return
;
}
this
.
getSegmentForValue
=
function
(
value
,
fallbackText
)
{
if
(
value
)
{
return
this
.
newSegment
(
value
);
}
else
{
return
this
.
newSegment
({
value
:
fallbackText
,
fake
:
true
});
}
};
this
.
newSelectMeasurement
=
function
()
{
return
new
MetricSegment
({
value
:
'select measurement'
,
fake
:
true
});
};
this
.
newFake
=
function
(
text
,
type
,
cssClass
)
{
return
new
MetricSegment
({
value
:
text
,
fake
:
true
,
type
:
type
,
cssClass
:
cssClass
});
};
this
.
newSegment
=
function
(
options
)
{
return
new
MetricSegment
(
options
);
};
this
.
newKey
=
function
(
key
)
{
return
new
MetricSegment
({
value
:
key
,
type
:
'key'
,
cssClass
:
'query-segment-key'
});
};
this
.
newKeyValue
=
function
(
value
)
{
return
new
MetricSegment
({
value
:
value
,
type
:
'value'
,
cssClass
:
'query-segment-value'
});
};
this
.
newCondition
=
function
(
condition
)
{
return
new
MetricSegment
({
value
:
condition
,
type
:
'condition'
,
cssClass
:
'query-keyword'
});
};
this
.
newOperator
=
function
(
op
)
{
return
new
MetricSegment
({
value
:
op
,
type
:
'operator'
,
cssClass
:
'query-segment-operator'
});
};
if
(
_
.
isString
(
options
))
{
this
.
value
=
options
;
this
.
html
=
$sce
.
trustAsHtml
(
templateSrv
.
highlightVariablesAsHtml
(
this
.
value
));
return
;
}
this
.
newOperators
=
function
(
ops
)
{
return
_
.
map
(
ops
,
function
(
op
)
{
return
new
MetricSegment
({
value
:
op
,
type
:
'operator'
,
cssClass
:
'query-segment-operator'
});
// temp hack to work around legacy inconsistency in segment model
this
.
text
=
options
.
value
;
this
.
cssClass
=
options
.
cssClass
;
this
.
custom
=
options
.
custom
;
this
.
type
=
options
.
type
;
this
.
fake
=
options
.
fake
;
this
.
value
=
options
.
value
;
this
.
selectMode
=
options
.
selectMode
;
this
.
type
=
options
.
type
;
this
.
expandable
=
options
.
expandable
;
this
.
html
=
options
.
html
||
$sce
.
trustAsHtml
(
templateSrv
.
highlightVariablesAsHtml
(
this
.
value
));
}
this
.
getSegmentForValue
=
function
(
value
,
fallbackText
)
{
if
(
value
)
{
return
this
.
newSegment
(
value
);
}
else
{
return
this
.
newSegment
({
value
:
fallbackText
,
fake
:
true
});
}
};
this
.
newSelectMeasurement
=
function
()
{
return
new
MetricSegment
({
value
:
'select measurement'
,
fake
:
true
});
};
this
.
newFake
=
function
(
text
,
type
,
cssClass
)
{
return
new
MetricSegment
({
value
:
text
,
fake
:
true
,
type
:
type
,
cssClass
:
cssClass
});
};
this
.
newSegment
=
function
(
options
)
{
return
new
MetricSegment
(
options
);
};
this
.
newKey
=
function
(
key
)
{
return
new
MetricSegment
({
value
:
key
,
type
:
'key'
,
cssClass
:
'query-segment-key'
});
};
this
.
newKeyValue
=
function
(
value
)
{
return
new
MetricSegment
({
value
:
value
,
type
:
'value'
,
cssClass
:
'query-segment-value'
});
};
this
.
newCondition
=
function
(
condition
)
{
return
new
MetricSegment
({
value
:
condition
,
type
:
'condition'
,
cssClass
:
'query-keyword'
});
};
this
.
newOperator
=
function
(
op
)
{
return
new
MetricSegment
({
value
:
op
,
type
:
'operator'
,
cssClass
:
'query-segment-operator'
});
};
this
.
newOperators
=
function
(
ops
)
{
return
_
.
map
(
ops
,
function
(
op
)
{
return
new
MetricSegment
({
value
:
op
,
type
:
'operator'
,
cssClass
:
'query-segment-operator'
});
});
};
this
.
transformToSegments
=
function
(
addTemplateVars
,
variableTypeFilter
)
{
return
function
(
results
)
{
let
segments
=
_
.
map
(
results
,
function
(
segment
)
{
return
self
.
newSegment
({
value
:
segment
.
text
,
expandable
:
segment
.
expandable
});
});
};
this
.
transformToSegments
=
function
(
addTemplateVars
,
variableTypeFilter
)
{
return
function
(
results
)
{
var
segments
=
_
.
map
(
results
,
function
(
segment
)
{
return
self
.
newSegment
({
value
:
segment
.
text
,
expandable
:
segment
.
expandable
});
if
(
addTemplateVars
)
{
_
.
each
(
templateSrv
.
variables
,
function
(
variable
)
{
if
(
variableTypeFilter
===
void
0
||
variableTypeFilter
===
variable
.
type
)
{
segments
.
unshift
(
self
.
newSegment
({
type
:
'value'
,
value
:
'$'
+
variable
.
name
,
expandable
:
true
}));
}
});
}
if
(
addTemplateVars
)
{
_
.
each
(
templateSrv
.
variables
,
function
(
variable
)
{
if
(
variableTypeFilter
===
void
0
||
variableTypeFilter
===
variable
.
type
)
{
segments
.
unshift
(
self
.
newSegment
({
type
:
'value'
,
value
:
'$'
+
variable
.
name
,
expandable
:
true
}));
}
});
}
return
segments
;
};
};
this
.
newSelectMetric
=
function
()
{
return
new
MetricSegment
({
value
:
'select metric'
,
fake
:
true
});
};
this
.
newPlusButton
=
function
()
{
return
new
MetricSegment
({
fake
:
true
,
html
:
'<i class="fa fa-plus "></i>'
,
type
:
'plus-button'
,
cssClass
:
'query-part'
});
return
segments
;
};
});
});
};
this
.
newSelectMetric
=
function
()
{
return
new
MetricSegment
({
value
:
'select metric'
,
fake
:
true
});
};
this
.
newPlusButton
=
function
()
{
return
new
MetricSegment
({
fake
:
true
,
html
:
'<i class="fa fa-plus "></i>'
,
type
:
'plus-button'
,
cssClass
:
'query-part'
,
});
};
}
coreModule
.
service
(
'uiSegmentSrv'
,
uiSegmentSrv
);
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