@@ -25,8 +25,7 @@ define(function(require) {
25
25
var angular = require ( 'angular' ) ;
26
26
27
27
return angular . module ( 'dataflowStreams.directives' , [ 'dataflowShared.services' , 'dataflowStreams.services' ] )
28
- //.directive('uniqueStreamName', ['DataflowUtils', 'StreamService', function (utils, streamService) {
29
- . directive ( 'uniqueStreamName' , [ 'DataflowUtils' , function ( utils ) {
28
+ . directive ( 'uniqueStreamName' , [ 'DataflowUtils' , 'StreamService' , function ( utils , streamService ) {
30
29
return {
31
30
require : 'ngModel' ,
32
31
link : function ( scope , elm , attrs , ctrl ) {
@@ -37,26 +36,20 @@ define(function(require) {
37
36
return utils . $q . when ( ) ;
38
37
}
39
38
40
- // For now consider everything valid (it will fail when the create operation
41
- // is actually driven if there is a real problem). Once there is a quiet
42
- // backend operation to check for stream existence, reactivate the code
43
- // below.
44
- return utils . $q . when ( ) ;
45
-
46
39
// This variant calls the API that currently logs an exception on the server.
47
- // var def = utils.$q.defer();
48
- // streamService.getSingleStreamDefinition(modelValue).then(function() {
49
- // // Success! Found stream with such name
50
- // def.reject('Stream with such name exists');
51
- // }, function(error) {
52
- // if (error.status === 404) {
53
- // def.resolve();
54
- // } else {
55
- // def.reject(error.statusText);
56
- // }
57
- // });
58
- //
59
- // return def.promise;
40
+ var def = utils . $q . defer ( ) ;
41
+ streamService . getSingleStreamDefinition ( modelValue ) . then ( function ( ) {
42
+ // Success! Found stream with such name
43
+ def . reject ( 'Stream with such name exists' ) ;
44
+ } , function ( error ) {
45
+ if ( error . status === 404 ) {
46
+ def . resolve ( ) ;
47
+ } else {
48
+ def . reject ( error . statusText ) ;
49
+ }
50
+ } ) ;
51
+
52
+ return def . promise ;
60
53
} ;
61
54
}
62
55
} ;
0 commit comments