Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor (use material2 builds) #6

Closed
wants to merge 17 commits into from

Conversation

tobiasschweizer
Copy link
Contributor

@tobiasschweizer tobiasschweizer commented Mar 28, 2018

I want to use material2 builds to implement a calendar switcher (custom header).

I put the github repo in the package.json. This creates conflicts with other dependencies. I tried to mark all other third party dependencies with a * to get the latest version.

During build I get:

ERROR in node_modules/@angular/material/input/typings/autosize.d.ts(8,37): error TS2307: Cannot find module '@angular/cdk/text-field'.
node_modules/@angular/material/input/typings/input.d.ts(7,33): error TS2307: Cannot find module '@angular/cdk/text-field'.
node_modules/@angular/material/stepper/typings/stepper.d.ts(29,5): error TS2416: Property '_stepHeader' in type 'MatStepper' is not assignable to the same property in base type 'CdkStepper'.
  Type 'QueryList<MatStepHeader>' is not assignable to type 'QueryList<ElementRef>'.
    Type 'MatStepHeader' is not assignable to type 'ElementRef'.
      Property 'nativeElement' is missing in type 'MatStepHeader'.
node_modules/@angular/material/tree/typings/data-source/flat-data-source.d.ts(9,46): error TS2307: Cannot find module '@angular/cdk/tree'.
node_modules/@angular/material/tree/typings/node.d.ts(9,73): error TS2307: Cannot find module '@angular/cdk/tree'.
node_modules/@angular/material/tree/typings/node.d.ts(17,22): error TS2420: Class 'MatTreeNode<T>' incorrectly implements interface 'CanDisable'.
  Property 'disabled' is missing in type 'MatTreeNode<T>'.
node_modules/@angular/material/tree/typings/node.d.ts(17,22): error TS2420: Class 'MatTreeNode<T>' incorrectly implements interface 'HasTabIndex'.
  Property 'tabIndex' is missing in type 'MatTreeNode<T>'.
node_modules/@angular/material/tree/typings/node.d.ts(32,22): error TS2420: Class 'MatNestedTreeNode<T>' incorrectly implements interface 'CanDisable'.
  Property 'disabled' is missing in type 'MatNestedTreeNode<T>'.
node_modules/@angular/material/tree/typings/node.d.ts(32,22): error TS2420: Class 'MatNestedTreeNode<T>' incorrectly implements interface 'HasTabIndex'.
  Property 'tabIndex' is missing in type 'MatNestedTreeNode<T>'.
node_modules/@angular/material/tree/typings/outlet.d.ts(8,35): error TS2307: Cannot find module '@angular/cdk/tree'.
node_modules/@angular/material/tree/typings/padding.d.ts(8,36): error TS2307: Cannot find module '@angular/cdk/tree'.
node_modules/@angular/material/tree/typings/toggle.d.ts(1,35): error TS2307: Cannot find module '@angular/cdk/tree'.
node_modules/@angular/material/tree/typings/tree.d.ts(1,25): error TS2307: Cannot find module '@angular/cdk/tree'.
src/app/modules/jdnconvertiblecalendardateadapter/adapter/index.ts(2,57): error TS2305: Module '"/Users/.../gitreps/JDNConvertibleCalendarDateAdapter/node_modules/@angular/material/material"' has no exported member 'MAT_DATE_LOCALE_PROVIDER'.

@mmalerba Could you help me here?

package.json Outdated
"core-js": "^2.5.1",
"hammerjs": "^2.0.8",
"@angular/animations": "*",
"@angular/cdk": "*",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Material & CDK 6.0.0-beta.5 is out now which I think should contain your change. You probably want to use that instead of the *-builds repos. For the rest of the Angular stuff you can use 6.0.0-rc.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba Thanks!

Now I get

ERROR in node_modules/@angular/common/src/location/location.d.ts(1,10): error TS2305: Module '"/Users/.../gitreps/JDNConvertibleCalendarDateAdapter/node_modules/rxjs/Rx"' has no exported member 'SubscriptionLike'.
src/app/modules/jdnconvertiblecalendardateadapter/adapter/index.ts(2,57): error TS2305: Module '"/Users/.../gitreps/JDNConvertibleCalendarDateAdapter/node_modules/@angular/material/material"' has no exported member 'MAT_DATE_LOCALE_PROVIDER'.

For error 1 I tried the solution mentioned here https://stackoverflow.com/questions/49446163/typescript-how-to-resolve-rxjs-rx-has-no-exported-member-subscriptionlike but then at runtime it did not work.

For error 2: Was MAT_DATE_LOCALE_PROVIDER removed from angular/material?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have rxjs 6.0.0-beta.1 in our package.json, you might need to update that too. Yes, we removed MAT_DATE_LOCALE_PROVIDER in favor of the new scoped injectables (see angular/components#10507). Theoretically this means you can just remove the reference to it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to update the @types libs?

I get these errors at build time

ERROR in node_modules/@angular/material/table/typings/table-data-source.d.ts(130,5): error TS2416: Property 'connect' in type 'MatTableDataSource<T>' is not assignable to the same property in base type 'DataSource<T>'.
  Type '() => BehaviorSubject<T[]>' is not assignable to type '(collectionViewer: CollectionViewer) => Observable<T[]>'.
    Type 'BehaviorSubject<T[]>' is not assignable to type 'Observable<T[]>'.
      Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'.
node_modules/@angular/material/tree/typings/data-source/flat-data-source.d.ts(80,5): error TS2416: Property 'connect' in type 'MatTreeFlatDataSource<T, F>' is not assignable to the same property in base type 'DataSource<F>'.
  Type '(collectionViewer: CollectionViewer) => Observable<F[]>' is not assignable to type '(collectionViewer: CollectionViewer) => Observable<F[]>'. Two different types with this name exist, but they are unrelated.
    Type 'Observable<F[]>' is not assignable to type 'Observable<F[]>'. Two different types with this name exist, but they are unrelated.
      Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'.
node_modules/@angular/material/tree/typings/data-source/nested-data-source.d.ts(23,5): error TS2416: Property 'connect' in type 'MatTreeNestedDataSource<T>' is not assignable to the same property in base type 'DataSource<T>'.
  Type '(collectionViewer: CollectionViewer) => Observable<T[]>' is not assignable to type '(collectionViewer: CollectionViewer) => Observable<T[]>'. Two different types with this name exist, but they are unrelated.
    Type 'Observable<T[]>' is not assignable to type 'Observable<T[]>'. Two different types with this name exist, but they are unrelated.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure why that's happening. Here's what our own package.json looked like as of the 6.0.0-beta.5 release: https://github.com/angular/material2/blob/0e37d6cdd73b49923d06add54e0d34bd9d256eda/package.json

Make sure your dependencies are at a high enough version, delete your package-lock.json and node_modules/ and then run npm i. Hopefully that should make it work. (There may be breakages in your code, since these are new major versions, but it should at least get rid of the errors coming from the Angular Material code).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it works now:-) Thanks!

@tobiasschweizer
Copy link
Contributor Author

tobiasschweizer commented Apr 3, 2018

@mmalerba Now this implementation of DateAdapter keeps track of the currently selected calendar format (see 03445c9). Now it should be possible to switch back and forth between Gregorian and Julian dates and manipulate them as you wish.

Once angular/components#10633 is merged, I can use the default header.

@tobiasschweizer
Copy link
Contributor Author

@mmalerba Thanks, I will try with npm i @angular/cdk@next @angular/material@next :-) to use the default calendar header with the calendar switch prepended. I will try find a solution for styling problems (it gets a little out of bounds with the calendar switch).

<mat-option *ngFor="let cal of supportedCalendarFormats" [value]="cal">{{cal}}</mat-option>
</mat-select>
</mat-form-field>
<div class="custom-header">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba If I try to use <mat-calendar-header></mat-calendar-header> instead I get

compiler.js:215 Uncaught Error: Template parse errors:
No provider for MatCalendar ("
      <button mat-icon-button (click)="nextClicked('year')">&gt;&gt;</button>
    </div>
    [ERROR ->]<mat-calendar-header></mat-calendar-header>
  "): ng:///AppModule/HeaderComponent.html@13:4
    at syntaxError (compiler.js:215)
    at TemplateParser.parse (compiler.js:14692)
    at JitCompiler._parseTemplate (compiler.js:22632)
    at JitCompiler._compileTemplate (compiler.js:22619)
    at eval (compiler.js:22562)
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:22562)
    at eval (compiler.js:22472)
    at Object.then (compiler.js:206)
    at JitCompiler._compileModuleAndComponents (compiler.js:22471)

However, if I use <mat-year-view></mat-year-view>it works just fine.

I am using 6.0.0-rc.3.

Is there still something missing to export MatCalendarHeader? Or is the export you made not included yet in 6.0.0-rc.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebStorm complains about mat-calendar-header:

mat-calendar-header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Default header for MatCalendar */
@Component({
  moduleId: module.id,
  selector: 'mat-calendar-header',
  templateUrl: 'calendar-header.html',
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
/**
 * An internal component used to display a single year in the datepicker.
 * @docs-private
 */
@Component({
  moduleId: module.id,
  selector: 'mat-year-view',
  templateUrl: 'year-view.html',
  exportAs: 'matYearView',
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush
})

There is no exportAs for MatCalendarHeader. Is that needed to use the selector outside of material?

@mmalerba
Copy link

mmalerba commented Apr 13, 2018 via email

@mmalerba
Copy link

mmalerba commented Apr 13, 2018 via email

@tobiasschweizer
Copy link
Contributor Author

tobiasschweizer commented Apr 13, 2018

@mmalerba Ok, I can make a PR for that (angular/components#10856). The CLA is not a problem anymore :-)


this._calendar._dateSelected(convertedDate);

this._calendar.ngAfterContentInit();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba

After the change of the calendar format, the month view is not updated (today's date is still in the old calendar format and also the new calendar date could be in the previous or next month).

See https://www.dropbox.com/s/mdkp6b5bv76uwsd/month_view.mov?dl=0

If the calendar is toggled, it works. Could the event be triggered from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view can be updated using _goToDateInView, see b1891b3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that these methods are not meant to be exposed to the outside. Should we add them to the public api?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try injecting the ChangeDetectorRef and calling markForCheck()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can inject it but today's date does not get updated (the circle stays with the old date).

However, if I change the month with the arrow controls (previousClicked, nextClicked), it gets updated.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, it's because the views only check today's date on init. In that case I think what you're doing should be ok (calling ngAfterContentInit), even though it looks kind of weird at a glance. I would just put a comment explaining why you're doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but probably we will need another solution once JDNConvertibleCalendar supports additional calendar formats that would require a reinit because the amount of months could be different and the names would be different too (e.g., if you convert from Gregorian to Hebrew calendar).

Btw: I will be away for the next two weeks having some time off :-)
Thanks for all your helpful advice:-)


// update the calendar UI after date format conversion
// TODO: today's date is not reset correctly
this._calendar.ngAfterContentInit();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba today's date is still not updated correctly (circle in UI). I would be glad for any suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@mmalerba mmalerba May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to call init on the various view themselves, rather than the calendar:

let view = this._calendar.currentView == 'month' ? this._calendar.monthView :
    (this._calendar.currentView == 'year ? this._calendar.yearView :
        this._calendar.multiYearView);
view.ngAfterContentInit();

If you want to send a PR adding a updateTodaysDate() method to the datepicker, I would be ok with that. This solution seems kind of messy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will try that!

<mat-select placeholder="Calendar Format" [formControl]="form.controls['calendar']">
<mat-option *ngFor="let cal of supportedCalendarFormats" [value]="cal">{{cal}}</mat-option>
</mat-select>
<mat-calendar-header></mat-calendar-header>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba This works now :-) (angular/components#10856)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmalerba done in 00231b6

If you want to send a PR adding a updateTodaysDate() method to the datepicker, I would be ok with that. This solution seems kind of messy.

I agree. What about a general method to do a clean reinit? Once we add more calendar formats, the names of the months etc. may be completely different, so we need to reinit the whole thing.

@tobiasschweizer
Copy link
Contributor Author

@mmalerba I would like to resolve #5 before merging this. The problem is that we did not use the angular compiler so far, and tsc removed the decorators.

@tobiasschweizer
Copy link
Contributor Author

this PR is replaced by #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants