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
89aea278
Commit
89aea278
authored
Oct 20, 2017
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
graphite: improved version comparison
parent
c22a192b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
10 deletions
+89
-10
public/app/core/utils/version.ts
+28
-0
public/app/plugins/datasource/graphite/datasource.ts
+2
-1
public/app/plugins/datasource/graphite/gfunc.js
+4
-9
public/test/core/utils/version_specs.ts
+55
-0
No files found.
public/app/core/utils/version.ts
0 → 100644
View file @
89aea278
const
versionPattern
=
/
(\d
+
)(?:\.(\d
+
))?(?:\.(\d
+
))?(?:
-
([
0-9A-Za-z
\.]
+
))?
/
;
export
class
SemVersion
{
major
:
number
;
minor
:
number
;
patch
:
number
;
meta
:
string
;
constructor
(
version
:
string
)
{
let
match
=
versionPattern
.
exec
(
version
);
if
(
match
)
{
this
.
major
=
Number
(
match
[
1
]);
this
.
minor
=
Number
(
match
[
2
]
||
0
);
this
.
patch
=
Number
(
match
[
3
]
||
0
);
this
.
meta
=
match
[
4
];
}
}
isGtOrEq
(
version
:
string
):
boolean
{
let
compared
=
new
SemVersion
(
version
);
return
!
(
this
.
major
<
compared
.
major
||
this
.
minor
<
compared
.
minor
||
this
.
patch
<
compared
.
patch
);
}
}
export
function
isVersionGtOrEq
(
a
:
string
,
b
:
string
):
boolean
{
let
a_semver
=
new
SemVersion
(
a
);
return
a_semver
.
isGtOrEq
(
b
);
}
public/app/plugins/datasource/graphite/datasource.ts
View file @
89aea278
...
...
@@ -2,6 +2,7 @@
import
_
from
'lodash'
;
import
*
as
dateMath
from
'app/core/utils/datemath'
;
import
{
isVersionGtOrEq
}
from
'app/core/utils/version'
;
/** @ngInject */
export
function
GraphiteDatasource
(
instanceSettings
,
$q
,
backendSrv
,
templateSrv
)
{
...
...
@@ -360,5 +361,5 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
}
function
supportsTags
(
version
:
string
):
boolean
{
return
version
>=
'1.1'
;
return
isVersionGtOrEq
(
version
,
'1.1'
)
;
}
public/app/plugins/datasource/graphite/gfunc.js
View file @
89aea278
define
([
'lodash'
,
'jquery'
'jquery'
,
'app/core/utils/version'
],
function
(
_
,
$
)
{
function
(
_
,
$
,
version
)
{
'use strict'
;
var
index
=
[];
...
...
@@ -944,13 +945,7 @@ function (_, $) {
};
function
isVersionRelatedFunction
(
func
,
graphiteVersion
)
{
return
isVersionGreaterOrEqual
(
graphiteVersion
,
func
.
version
)
||
!
func
.
version
;
}
function
isVersionGreaterOrEqual
(
a
,
b
)
{
var
a_num
=
Number
(
a
);
var
b_num
=
Number
(
b
);
return
a_num
>=
b_num
;
return
version
.
isVersionGtOrEq
(
graphiteVersion
,
func
.
version
)
||
!
func
.
version
;
}
return
{
...
...
public/test/core/utils/version_specs.ts
0 → 100644
View file @
89aea278
import
{
describe
,
beforeEach
,
it
,
expect
}
from
'test/lib/common'
;
import
{
SemVersion
,
isVersionGtOrEq
}
from
'app/core/utils/version'
;
describe
(
"SemVersion"
,
()
=>
{
let
version
=
'1.0.0-alpha.1'
;
describe
(
'parsing'
,
()
=>
{
it
(
'should parse version properly'
,
()
=>
{
let
semver
=
new
SemVersion
(
version
);
expect
(
semver
.
major
).
to
.
be
(
1
);
expect
(
semver
.
minor
).
to
.
be
(
0
);
expect
(
semver
.
patch
).
to
.
be
(
0
);
expect
(
semver
.
meta
).
to
.
be
(
'alpha.1'
);
});
});
describe
(
'comparing'
,
()
=>
{
beforeEach
(()
=>
{
version
=
'3.4.5'
;
});
it
(
'should detect greater version properly'
,
()
=>
{
let
semver
=
new
SemVersion
(
version
);
let
cases
=
[
{
value
:
'3.4.5'
,
expected
:
true
},
{
value
:
'3.4.4'
,
expected
:
true
},
{
value
:
'3.4.6'
,
expected
:
false
},
{
value
:
'4'
,
expected
:
false
},
{
value
:
'3.5'
,
expected
:
false
},
];
cases
.
forEach
((
testCase
)
=>
{
expect
(
semver
.
isGtOrEq
(
testCase
.
value
)).
to
.
be
(
testCase
.
expected
);
});
});
});
describe
(
'isVersionGtOrEq'
,
()
=>
{
it
(
'should compare versions properly (a >= b)'
,
()
=>
{
let
cases
=
[
{
values
:
[
'3.4.5'
,
'3.4.5'
],
expected
:
true
},
{
values
:
[
'3.4.5'
,
'3.4.4'
]
,
expected
:
true
},
{
values
:
[
'3.4.5'
,
'3.4.6'
],
expected
:
false
},
{
values
:
[
'3.4'
,
'3.4.0'
],
expected
:
true
},
{
values
:
[
'3'
,
'3.0.0'
],
expected
:
true
},
{
values
:
[
'3.1.1-beta1'
,
'3.1'
],
expected
:
true
},
{
values
:
[
'3.4.5'
,
'4'
],
expected
:
false
},
{
values
:
[
'3.4.5'
,
'3.5'
],
expected
:
false
},
];
cases
.
forEach
((
testCase
)
=>
{
expect
(
isVersionGtOrEq
(
testCase
.
values
[
0
],
testCase
.
values
[
1
])).
to
.
be
(
testCase
.
expected
);
});
});
});
});
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